Navigation Drawer Item Icon Not Showing Original Colour

Navigation drawer item icon not showing original colour

I found the answer here: https://stackoverflow.com/a/30632980/875249

To avoid the link its pretty straightforward:

    mNavigationView.setItemIconTintList(null);

This disables all state based tinting, but you can also specify your own list too. It worked great for me!

Here is where you can get the details on creating a color state list, but its pretty simple too:
http://developer.android.com/reference/android/content/res/ColorStateList.html

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="@color/primary" />
<item android:state_checked="false" android:color="@android:color/white" />
</selector>

How to show original color of icon in Android Navigation drawer?

Force NavigationView to stop tinting the icons in MainActivity.java:

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setItemIconTintList(null);

Navigation Drawer Icon Color

This issue is duplicated.
But I add answer for explanation.

Your layout file is like this:
(activity_main.xml)

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!-- The main content view -->
...

<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/navigation_item"/>

</android.support.v4.widget.DrawerLayout>

Your Activity is like this: (MainActivity.java)

Call navigationView.setItemIconTintList.

public class MainActivity extends AppCompatActivity {
...

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

...

NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view);
navigationView.setItemIconTintList(null);

...
}
...
}

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.

Change color of Navigation Drawer Icon in Android Studio default template

Based on @MD's comment, all I needed to do was add:

app:itemIconTint="@color/my_desired_colour"

to NavigationView (it is located in activity_main.xml layout file) The default tint is black but you can use an even darker shade of black by using #000000

 <android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:itemIconTint="#000000"
app:menu="@menu/activity_main_drawer" />

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 :)

How to change the colour of the navigation drawer item

I solved it setting this attribute to my NavigationView app:itemBackground="@drawable/drawer_selector"

and my drawer_selector is as below

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/white" />
<item android:state_focused="true" android:drawable="@color/white" />
<item android:state_activated="true" android:drawable="@color/white" />
<item android:drawable="@color/orange" />

Navigation drawer item icon not showing original colour

I found the answer here: https://stackoverflow.com/a/30632980/875249

To avoid the link its pretty straightforward:

    mNavigationView.setItemIconTintList(null);

This disables all state based tinting, but you can also specify your own list too. It worked great for me!

Here is where you can get the details on creating a color state list, but its pretty simple too:
http://developer.android.com/reference/android/content/res/ColorStateList.html

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="@color/primary" />
<item android:state_checked="false" android:color="@android:color/white" />
</selector>


Related Topics



Leave a reply



Submit