当我们使用app:showAsAction ="always"时,更改选项菜单的文本颜色. [英] Change text color of option menu when we use app:showAsAction="always"

查看:94
本文介绍了当我们使用app:showAsAction ="always"时,更改选项菜单的文本颜色.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用工具栏,并使用选项执行相应的操作.我的问题是,我想在工具栏上用白色显示保存"文本,我应用了多种样式,但始终显示为黑色.但是,当选项出现弹出然后文本颜色始终为白色.我在Google上搜索了很多,但没有解决方案.

I am using toolbar and use option for corresponding actions. My problem is this I want to show "SAVE" text on toolbar with white color, I apply many styles but it always appear as black. But when option appear as popup then text color is always white . I google this a lot , but have no solution.

这是我的代码:

工具栏

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/tools"
    android:id="@+id/my_awesome_toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    app:theme="@android:style/ThemeOverlay.Material.Light"
    app:popupTheme="@style/Theme.AppCompat.NoActionBar"
    android:background="@drawable/tb_header"
    android:minHeight="?attr/actionBarSize"/>

样式

 <style name="MStyle" parent="Theme.AppCompat.Light.NoActionBar">

 <item name="android:windowBackground">@android:color/white</item>
        <item name="android:colorBackground">@android:color/black</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="android:textAllCaps">false</item>
        <item name="android:popupMenuStyle">@style/MyPopupMenu</item>
        <item name="android:panelBackground">@android:color/holo_green_light</item>
        <item name="android:actionBarWidgetTheme">@style/AppTheme</item>

    </style>

<style name ="MyPopupMenu" parent="android:Theme.Holo.Light">
        <item name="android:popupBackground">@android:color/holo_green_light</item>
    </style>


****Option menu**** 

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context="com.doubtfire.userprofiles.ParentProfileActivity">
    <item
        android:id="@+id/action_skip"
        android:title="@string/menu_str_skip"

        android:orderInCategory="100"
        app:showAsAction="always" />
</menu>


****I even apply code at onPrepareOptionMenu**** 



   @Override
        public boolean onPrepareOptionsMenu(Menu menu) {
            for (int i=0; i<menu.size(); i++) {
                MenuItem mi = menu.getItem(i);
                String title = mi.getTitle().toString();
                Spannable newTitle = new SpannableString(title);
                newTitle.setSpan(new ForegroundColorSpan(Color.WHITE), 0, newTitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                mi.setTitle(newTitle);
            }
            return true;
        }

推荐答案

使用

<item name="android:actionMenuTextColor">#FFFFFF</item>

MStyle中,如下所示:

<style name="MStyle" parent="Theme.AppCompat.Light.NoActionBar">

  ...

  <item name="android:actionMenuTextColor">#FFFFFF</item>
  <!-- for appcompat-->
  <item name="actionMenuTextColor">#FFFFFF</item>
</style>

当在ActionBar

这篇关于当我们使用app:showAsAction ="always"时,更改选项菜单的文本颜色.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆