Disable icon colorStateList in NavigationView
Is there no way for me to force NavigationView to stop tinting my
icons?
There sure is. You can do so programmatically using NavigationView.setItemIconTintList
.
And you can do so in your XML
layout by using the NavigationView.itemIconTint
attribute.
Programmatically
yourNavigationView.setItemIconTintList(null);
From XML
<android.support.design.widget.NavigationView
...
app:itemIconTint="@android:color/black"
... />
Results
Colored Icons In NavigationView
Yes you can add colored icon using menu group items:
<item
android:id="@+id/drawer_artist"
android:icon="@drawable/artist"
android:title="Artists"/>
And for highlighting the selcted item Use the code below for default selection:
navigationView.getMenu().getItem(0).setChecked(true);
And You can select(highlight) the item by calling
onNavigationItemSelected(navigationView.getMenu().getItem(0));
Edit
If you are using navigationview you can edit option for changing the colortint of icons as follows:
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:background="@drawable/bg_all"
app:itemIconTint="@android:color/white"
app:itemTextColor="@android:color/white"
app:theme="@style/list_item_appearance"
app:menu="@menu/drawer_menu" >
Edit
If you set navigationView.setItemIconTintList(null);
you will get colored icons.
How to set these kind of colored icon in navigation view of drawer layout
Add the following line after you have initialised Drawer Layout
and Navigation View
:
navigationView.setItemIconTintList(null);
navigationView
is your Navigation View
Variable
Android: Bottom Navigation View - change icon of selected item
You need to reset the icon onclick, and then on the switch case you need to set only the one you need to change, so only when selected the icon change.
Menu menu = bottomNavigationView.getMenu();
menu.findItem(R.id.action_favorites).setIcon(favDrawable);
switch (item.getItemId()) {
case R.id.action_favorites:
item.setIcon(favDrawableSelected);
case R.id.action_schedules:
case R.id.action_music:
}
How to change the text and icon color of selected menu item on Navigation Drawer programmatically using java
Firstly thank you all for responding back with your solutions :) Learning from the answers above and doing some research on ColorStateList
I finally managed to create a method
which sets the color of the checked item on the navigation drawer to match the color of my app theme color which is generated randomly at runtime.
Here's the method:
public void setNavMenuItemThemeColors(int color){
//Setting default colors for menu item Text and Icon
int navDefaultTextColor = Color.parseColor("#202020");
int navDefaultIconColor = Color.parseColor("#737373");
//Defining ColorStateList for menu item Text
ColorStateList navMenuTextList = new ColorStateList(
new int[][]{
new int[]{android.R.attr.state_checked},
new int[]{android.R.attr.state_enabled},
new int[]{android.R.attr.state_pressed},
new int[]{android.R.attr.state_focused},
new int[]{android.R.attr.state_pressed}
},
new int[] {
color,
navDefaultTextColor,
navDefaultTextColor,
navDefaultTextColor,
navDefaultTextColor
}
);
//Defining ColorStateList for menu item Icon
ColorStateList navMenuIconList = new ColorStateList(
new int[][]{
new int[]{android.R.attr.state_checked},
new int[]{android.R.attr.state_enabled},
new int[]{android.R.attr.state_pressed},
new int[]{android.R.attr.state_focused},
new int[]{android.R.attr.state_pressed}
},
new int[] {
color,
navDefaultIconColor,
navDefaultIconColor,
navDefaultIconColor,
navDefaultIconColor
}
);
mNavView.setItemTextColor(navMenuTextList);
mNavView.setItemIconTintList(navMenuIconList);
}
you can call this method with any int color
you want :)
Selected tab's color in Bottom Navigation View
While making a selector
, always keep the default state at the end, otherwise only default state would be used. You need to reorder the items in your selector as:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="@android:color/holo_blue_dark" />
<item android:color="@android:color/darker_gray" />
</selector>
And the state to be used with BottomNavigationBar
is state_checked
not state_selected
.
Related Topics
Use 32-Bit Jni Libraries on 64-Bit Android
Change Navigation Bar Icon Color on Android
Android Service Startservice() and Bindservice()
Onactivityresult Do Not Fire If Launch Mode of Activity Is Singleinstance
How to Disable Viewpager Adapter on Touching Specific Views
How to Import an Existing Project from Github into Android Studio
Difference Between Getview & Getdropdownview in Spinneradapter
Get Context of Test Project in Android Junit Test Case
How to Force Audio Through The Speakers When Headphones Are Plugged In
Android Studio: "Use Default Gradle Wrapper" VS. "Use Customizable Gradle Wrapper"
Sending Message to a Handler on a Dead Thread When Getting a Location from an Intentservice
Is Discard Bad for Program Performance in Opengl
How to Fetch Data from a Web Server in an Android Application
How to Restrict My Edittext Input to Numerical (Possibly Decimal and Signed) Input