简体   繁体   中英

Changing text color of menu heading title item in navigation drawer

I'm trying to implement dark mode in my application. I've implemented on menu item. It is changing the color but what I want is to change the color of heading as well because when dark mode is implemented the heading menu is hidden as the color is light grey.

Navigation Menu:

   <android.support.design.widget.NavigationView
    android:id="@+id/navigation"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="?attr/bgColor"
    app:itemTextColor="?attr/textColor"
    app:headerLayout="@layout/nav_header_home"
    app:menu="@menu/nav_items" />

轻主题

黑暗主题

Add <item name="android:textColorSecondary">@color/white</item> inside your AppTheme and AppTheme.NoActionBar styles.xml file like this:

<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>

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

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>

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

where the color value <color name="white">#FFFFFF</color> is placed in colors.xml .

The result looks exactly like you wanted:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM