Navigation drawer item icon not showing original colour

前端 未结 9 2112
一个人的身影
一个人的身影 2020-11-28 18:46

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 (bro

相关标签:
9条回答
  • 2020-11-28 19:16

    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
    
    0 讨论(0)
  • 2020-11-28 19:24

    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>
    
    0 讨论(0)
  • 2020-11-28 19:26

    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.

    0 讨论(0)
提交回复
热议问题