How to change toolbar menu item text color for pre Lollipop and Lollipop versions

六眼飞鱼酱① 提交于 2019-12-01 08:51:58

问题


I am using Toolbar for the purpose of material design in my application. Everything working fine but except when it comes to change the menu item text color I am completely stuck up with the solution. I am also posting screenshot of the text that should be taken and code I am using in my application for your reference. I tried several alternate methods like assigning as follows

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

<item name="android:textColor">#000</item>

But known of the above solutions works for me.

Requirement screenshot:

Need to change SKIP menu item from black to white color.

styles.xml

<style name="ToolBarTheme" parent="@style/Theme.AppCompat.Light">
        <item name="colorPrimary">@color/blue</item>
        <item name="colorPrimaryDark">@color/blue</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
        <item name="android:actionMenuTextColor">@color/white</item>
        <item name="android:textColor">#000</item>

    </style>

toolbar.xml

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:layout_scrollFlags="scroll|enterAlways"
    android:fitsSystemWindows="true"
    android:background="?attr/colorPrimary"/>

manifests

<activity
            android:name=".activity.HomeActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="keyboard|screenLayout|orientation"
            android:theme="@style/ToolBarTheme"></activity>

I really dont know where I am committing mistake. Please help me. Thanks in advance


回答1:


Change this

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

to

<item name="actionMenuTextColor">@color/white</item>

And apply the theme to the toolbar:

android:theme="@style/ToolBarTheme"

You style your widgets and provide themes for your activity.



来源:https://stackoverflow.com/questions/32181278/how-to-change-toolbar-menu-item-text-color-for-pre-lollipop-and-lollipop-version

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