Navigation drawer item icon not showing original colour

JavaAndroidXmlAndroid Support-Library

Java Problem Overview


I'm trying to show an icon next to an item within my menu for my navigation drawer, but for some reason the icon always appears in grey rather than the original colour (brown). Is there any way of preventing this from happening in order to show the icon's original colour?

MainActivity.java

public class MainActivity extends AppCompatActivity {

    private DrawerLayout mDrawerLayout;

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

        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        if (navigationView != null) {
            setupDrawerContent(navigationView);
        }
    }

    private void setupDrawerContent(NavigationView navigationView) {
        navigationView.setNavigationItemSelectedListener(
                new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(MenuItem menuItem) {
                mDrawerLayout.closeDrawers();

                return true;
            }
        });
    }
}

drawer_view.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:title="Section">
        <menu>
            <item
                android:id="@+id/navigation_item_1"
                android:icon="@drawable/ic_browncircle"
                android:title="Sub item 1" />
        </menu>
    </item>
</menu>

enter image description here

Java Solutions


Solution 1 - Java

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>

Solution 2 - Java

Use

    mNavigationView.setItemIconTintList(null);

it's right. Also If all your icons in one color scheme (i had all white) you can setup through xml file - app:itemIconTint="@android:color/white"

My case:

<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:clickable="true"
    app:headerLayout="@layout/nav_header_main"
    app:itemTextColor="@android:color/white"
    app:menu="@menu/activity_main_drawer"
    android:background="@android:color/black"
    app:itemIconTint="@android:color/white"
    />

Solution 3 - Java

I've tried something similar in one of my app. And yes, it appears that the icon color doesn't change. But I've managed to do with another workaround. Here's my ic_browncircle.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval"
    android:tint="@color/brown"
    >
  <size
      android:height="3dp"
      android:width="3dp"
      />
  <solid android:color="@color/brown"/>
</shape>

Which I believe is something similar to you but it doesn't have any effect and doesn't change the color.

So what I did is this.

navigationView.getMenu()
    .findItem(R.id. navigation_item_1)
    .getIcon()
    .setColorFilter(Color.parseColor("#b69260"), PorterDuff.Mode.SRC_ATOP);

And it seems working. Here's the result.

enter image description here

Solution 4 - Java

If you create a project with navigation drawer which the Android Studio provided. In your Main Activity class, you can just simply add this line of code navigationView.setItemIconTintList(null); to your onCreate method. Like this;

 NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
 navigationView.setNavigationItemSelectedListener(this);
 navigationView.setItemIconTintList(null); // <----- HERE
 setupDrawerContent(navigationView);

Solution 5 - Java

You can try using a tinted drawable, not sure if it works below 5.0.

Create a drawable and add the following code.

<?xml version="1.0" encoding="utf-8"?>
<bitmap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/ic_browncircle"
    android:tint="@color/brownColor"/>

And then change your menu item drawable to the one you just created. If that doesn't work, then I'm not sure of any other solutions. You can try this library: https://github.com/mikepenz/MaterialDrawer I use it a lot in my projects.

Solution 6 - Java

Just add one line in xml

> app:itemIconTint="@color/white"

Solution 7 - Java

Some how this code not working MainActivity.java

                NavigationView.setItemIconTintList(null); // not working

so you can use it.

MainActivity.java

 NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
   navigationView.setNavigationItemSelectedListener(this); 
   navigationView.setItemIconTintList(null); // <-- HERE add this code for icon color

Solution 8 - Java

I found a solution.

1) Go to the Design tab
2) Click on navView
3) Search itemicontint in properties
4) Write null and press Enter

Solution 9 - Java

Add this

 android:tint="@color/colorPrimary"

Solution 10 - Java

 BottomNavigationView navigationbtn = findViewById(R.id.bottomNavigationView);

 BottomNavigationMenuView mbottomNavigationMenuView =
                (BottomNavigationMenuView) navigationbtn.getChildAt(0);

       View view3 = mbottomNavigationMenuView.getChildAt(2);

       BottomNavigationItemView itemView3 = (BottomNavigationItemView) view3;

        itemView3.setIconTintList(null);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionwbk727View Question on Stackoverflow
Solution 1 - JavaChrisView Answer on Stackoverflow
Solution 2 - JavaChuckView Answer on Stackoverflow
Solution 3 - JavaYe Lin AungView Answer on Stackoverflow
Solution 4 - JavaDavid AdamView Answer on Stackoverflow
Solution 5 - JavaAustin HodakView Answer on Stackoverflow
Solution 6 - JavaHarsh SinghalView Answer on Stackoverflow
Solution 7 - JavaParbanView Answer on Stackoverflow
Solution 8 - Javaidrees khanView Answer on Stackoverflow
Solution 9 - JavaNull Pointer ExceptionView Answer on Stackoverflow
Solution 10 - JavaDilip LoharView Answer on Stackoverflow