Navigation Box Item Icon Not Displaying Original Color

I'm trying to show an icon next to an item in my menu for my navigation box, but for some reason the icon is always grayed out rather than the original (brown). Is there a way to prevent this from showing the original color of the icon?

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

+86
java android xml android-support-library
Jul 13 '15 at 22:04
source share
5 answers

I found the answer here: stack overflow

To avoid the link, this is pretty simple:

  mNavigationView.setItemIconTintList(null); 

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

Here you can get information about creating a list of color states, but its pretty simple: 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> 
+207
Aug 13 '15 at 22:05
source share

Use

  mNavigationView.setItemIconTintList(null); 

it is right. Also, if all your icons are in the same color scheme (I had white) you can configure through the 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" /> 
+24
Oct 06 '16 at 12:27
source share

I tried something like this in one of my applications. And yes, it looks like the color of the icon is not changing. But I managed to make another workaround. Here is 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> 

I think this is something similar to you, but it has no effect and does not change color.

So I did it.

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

And it seems working. Here is the result.

enter image description here

+4
Jul 14 '15 at 5:22
source share

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

Create a drawing 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 to the one you just created. If this does not work, I am not sure about any other solutions. You can try this library: https://github.com/mikepenz/MaterialDrawer I use a lot in my projects.

+3
Jul 14 '15 at
source share

Just add one line in xml

app:itemIconTint="@color/white"

0
Jun 05 '17 at 7:15
source share



All Articles