How to change the navigation icon color

和自甴很熟 提交于 2019-12-31 05:40:12

问题


I have a navigationView in my app and after add two lines in app style :

<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>

The Navigation icon color changed to black and for this problem i added this line in style :

<item name="android:textColorSecondary">@android:color/white</item>

Now navigation icon is white again but now i have a new problem . With above code , the title of navigation items is change color too.

I didn't find a solution to this Interference

Style :

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:textColorSecondary">@android:color/white</item>

</style>

Navigation Menu :

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:showIn="navigation_view">

    <group
        android:id="@+id/testGRP"
        android:checkableBehavior="single"
        >
    <item android:title="جلسه : انتخاب نشده"
        android:id="@+id/menuItem_StudentList11"
        android:icon="@drawable/ic_arrow_drop_up"
        />

    <item android:title="مرتب سازی"
        android:id="@+id/menuItem_StudentList_Quize1"
        android:icon="@drawable/all_exam_icon"
        />

        <item android:title="@string/Navigation_StudentList3"
            android:id="@+id/menuItem_StudentList_Quize"
            android:icon="@drawable/all_exam_icon"
            />

    </group>


    <item android:title="رویدادها:"> //this line is title

    <menu>

    <item android:title="@string/Navigation_StudentList4"
        android:id="@+id/menuItem_StudentList_MidTerm"
        android:icon="@drawable/all_exam_icon"
        />

    <item android:title="@string/Navigation_StudentList5"
        android:id="@+id/menuItem_StudentList_EndTerm"
        android:icon="@drawable/all_exam_icon"
        />

    <item android:title="امتحان عملی"
        android:id="@+id/menuItem_StudentList_Practical"
        android:icon="@drawable/all_exam_icon"
        />


    <item android:title="@string/Navigation_StudentList6"
        android:id="@+id/menuItem_StudentList_Project"
        android:icon="@drawable/all_projcet_icon"
        />


    <item android:title="@string/Navigation_StudentList2"
        android:id="@+id/menuItem_StudentList_Conference"
        android:icon="@drawable/all_conference_icon"
        />
    </menu>
        </item>


    <item android:title="@string/Navigation_StudentList1"
        android:id="@+id/menuItem_StudentList1"
        android:icon="@drawable/all_notifiicon_icon"
        />

    <item android:title="@string/Navigation_StudentList7"
        android:id="@+id/menuItem_StudentList7"
        android:icon="@drawable/main_newclass_icon"
        />
</menu>

enter image description here

enter image description here


回答1:


Using a Toolbar, to change the navigation icon color you can use:

With a MaterialToolbar or (androidx and a Material theme):

<com.google.android.material.appbar.MaterialToolbar
    android:theme="@style/MyThemeOverlay_Toolbar"
    ...>

  <style name="MyThemeOverlay_Toolbar" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">
    <!-- color used by navigation icon and overflow icon -->
    <item name="colorOnPrimary">@color/secondaryColor</item>
  </style>

With the support Library:

<android.support.v7.widget.Toolbar
  app:theme="@style/ThemeToolbar" />


<style name="ThemeToolbar" parent="Theme.AppCompat.Light">
   <!-- navigation icon color -->
   <item name="colorControlNormal">@color/my_color</item>
</style>



回答2:


If you are looking to change text colors/appearance in the NavigationView Items, you should use the attribs

  • app:itemTextColor
  • app:itemIconTint
  • app:itemTextAppearance

Otherwise, Specify which view's color you want to change. Setting android:textColorSeconday is a bad idea according to me.



来源:https://stackoverflow.com/questions/58074174/how-to-change-the-navigation-icon-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!