如何更改导航图标的颜色

如何更改导航图标的颜色

本文介绍了如何更改导航图标的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有一个NavigationView,然后以应用程序样式添加两行:

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

样式:

<!-- 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>

导航菜单:

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

在此处输入图片描述

在此处输入图片描述

推荐答案

使用Toolbar来更改导航图标的颜色,您可以使用:

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

使用 MaterialToolbar 或(androidx和Material主题):

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>

带有支持库:

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

这篇关于如何更改导航图标的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:37