Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
343 views
in Technique[技术] by (71.8m points)

android - Change Toolbar Menu Item color (non-hidden action)

Say I have a menu (options_menu.xml) similar to the following:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto" >
    <item android:id="@+id/action_login"
          android:title="Login"
          app:showAsAction="always"/>
</menu>

which I inflate into the new Toolbar item

mToolbar.inflateMenu(R.menu.options_home);

This results in something like

enter image description here

Is there a way to change this text color without using an image, changing the rest of the Toolbar text color, or by adding a custom view to the toolbar? Looking for an answer for minSdk 15 (appcompat).

Update:

My relevant style:

<style name="AppTheme" parent="AppTheme.Base">
    <item name="actionMenuTextColor">@color/ww_red</item>
</style>

<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/red</item>
    <item name="colorAccent">@color/theme_accent</item>

    <item name="android:textColor">@color/text_dark</item>

    <item name="android:colorEdgeEffect">@color/gray</item>
</style>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In your theme file you have to put this :

<style name="AppTheme.ActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
         ...
    <item name="actionMenuTextColor">@color/text_color</item>
         ...
</style>

and apply this theme to your Toolbar view like this :

<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/main_toolbar"
   android:layout_width="match_parent"
   android:layout_height="?attr/actionBarSize"
   android:background="?attr/colorPrimary"
   android:layout_gravity="top"
   app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
   android:theme="@style/AppTheme.ActionBar"/>

android:theme="@style/AppTheme.ActionBar" don't forget this line in your toolbar


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...