Change color of Navigation Drawer Icon in Android Studio default template

前端 未结 9 982
北恋
北恋 2020-12-13 05:52

The new default Navigation Drawer Activity template in Android Studio

defines its titles and icons in a menu file activity_main_drawer like thi

相关标签:
9条回答
  • 2020-12-13 06:09

    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" />
    
    0 讨论(0)
  • 2020-12-13 06:09

    Create a new style:

    <style name="DrawerIconStyle" parent="Widget.AppCompat.DrawerArrowToggle">
        <item name="color">@android:color/red</item>
    </style>
    

    and in your theme, add this line:

    <item name="drawerArrowStyle">@style/DrawerIconStyle</item>
    
    0 讨论(0)
  • 2020-12-13 06:09

    In my case, I was having a style

     <style name="MyToolbarStyle" parent="Theme.AppCompat">
         <item name="actionOverflowButtonStyle">@style/ActionButtonOverflowStyle</item>
         <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
     </style>
     <style name="ActionButtonOverflowStyle">
            <item name="android:color">@color/colorPrimary</item>
        </style>
        <style name="DrawerArrowStyle">
            <item name="android:color">@color/colorPrimary</item>
        </style>
    

    and have applied the theme to the Appbar layout, so programatically chaining color didn't work.

    So, try removing any styles that you applied, in case you are not able to change the color of the icon and then try the above given solutions.

    0 讨论(0)
  • 2020-12-13 06:14

    add itmIconTint in navigation view

        <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:background="@drawable/drawerbackgtound"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:itemTextColor="@color/white"
        app:iconTint="#FFFFFF"
        app:itemIconTint="#FFFFFF"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />
    
    0 讨论(0)
  • 2020-12-13 06:26

    Based on @ojonugwa ochalifu and @MD's comment,

    You can achieve by writing app:itemIconTint but if you write this, the navigation drawers icon color will also be changed. The simple and easy solution that I found after lots of R&D is that you have define <item name="colorControlNormal">#FFE730</item> in theme of AppBarLayout or if you using Toolbar only without AppBarLayout, you can also write <item name="colorControlNormal">#FFE730</item> in theme or popupTheme of Toolbar in your xml.

    This will also change the color of activity's back arrow as well.

    Hope this helps you all who are facing this type of issue.

    0 讨论(0)
  • 2020-12-13 06:27

    This works for me for changing icon color from the menu xml file which you drag in the app:menu attribute of the NavigationView widget.

    Use app:iconTint attribute to set the icon color.

    <?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">
        <item
            android:id="@+id/..."
            android:icon="@drawable/ic_person_black_24dp"
            android:title="..."
            app:iconTint="#FFEB3B" />
        <item
            android:id="@+id//..."
            android:icon="@drawable/ic_settings_black_24dp"
            android:title="..."
            app:iconTint="#FFEB3B" />
    
        <item
            android:id="@+id//..."
            android:icon="@drawable/logout"
            android:title="..."
            app:iconTint="#FFEB3B"/>
    </menu>
    
    0 讨论(0)
提交回复
热议问题