Navigation drawer item icon not showing original colour

前端 未结 9 2111
一个人的身影
一个人的身影 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:04

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

    Just add one line in xml

    app:itemIconTint="@color/white"

    0 讨论(0)
  • 2020-11-28 19:09

    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

    0 讨论(0)
  • 2020-11-28 19:09

    Add this

     android:tint="@color/colorPrimary"
    
    0 讨论(0)
  • 2020-11-28 19:11

    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

    0 讨论(0)
  • 2020-11-28 19:12

    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"
        />
    
    0 讨论(0)
提交回复
热议问题