更改Android的PopupMenu的文本颜色不工作 [英] Changing Android PopupMenu text color is not working

查看:376
本文介绍了更改Android的PopupMenu的文本颜色不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

另一个Android主题风格的问题...因为我搜索的网站,并不能找到答案,这里是我的问题。

Another android theme style question... since I searched the site and can't find the answer here is my question.

我想通过改变操作栏显示溢出的弹出菜单的文本颜色,但它并没有改变。它改变这种背景下就好了,而不是文本颜色。顺便说一句,这是由Android的操作栏样式生成器生成的code,我刚添加的文本外观的标记。

I'm trying to change the text color of the PopupMenu shown by the action bar overflow, but It is not changing. It changes that background just fine, but not the text color. Btw this is code generated by "Android Action Bar Style Generator", I just added the Text appearance tag.

下面是我的code:

<style name="Theme.Styles_mr_action_bar" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="actionBarItemBackground">@drawable/selectable_background_styles_mr_action_bar</item>
    <item name="popupMenuStyle">@style/PopupMenu.Styles_mr_action_bar</item>
    <item name="dropDownListViewStyle">@style/DropDownListView.Styles_mr_action_bar</item>
    <item name="textAppearanceLargePopupMenu">@style/PopupMenu.TextAppearanceLarge</item>
    <item name="textAppearanceSmallPopupMenu">@style/PopupMenu.TextAppearanceSmall</item>
</style>


<style name="PopupMenu.Styles_mr_action_bar" parent="@style/Widget.AppCompat.Light.PopupMenu">
    <item name="android:popupBackground">@drawable/menu_dropdown_panel_styles_mr_action_bar</item>
</style>

<style name="PopupMenu.TextAppearanceSmall" parent="@style/TextAppearance.AppCompat.Light.Widget.PopupMenu.Small">
    <item name="android:textColor">#000000</item>
</style>

<style name="PopupMenu.TextAppearanceLarge" parent="@style/TextAppearance.AppCompat.Light.Widget.PopupMenu.Large">
    <item name="android:textColor">#000000</item>
</style>

任何线索发生了什么?我在安卓4.4.4测试它

Any clue what is happening? I'm testing it in android 4.4.4

推荐答案

好球员,因此我几乎花了一个星期试图改变这一点,但没有办法做到这一点。所以我做了什么?刚刚创建了一个弹出式窗口,它连接到一个看起来像一个溢出菜单中选择操作项目。

Ok guys so I spent almost a week trying to change this but there was no way to do it... So what did I do? just created a popup and attached it to an action item that looked like a overflow menu.

PopupMenu mPopupMenu = new PopupMenu(this, findViewById(R.id.fake_overflow_item));
mPopupMenu.getMenuInflater().inflate(R.menu.custom_popup_menu, mPopupMenu.getMenu());
mPopupMenu.setOnMenuItemClickListener(this);
mPopupMenu.show();

一些有关的PopupMenu的锚认为真正重要的是,你必须从你的活动与findViewById直接得到它()。如果从MenuItemCompat.getActionView()得到它,的弹出菜单将引发异常。我说明这一点,因为我有这个问题,无处是说,你必须从那里得到它。

something really important about the anchor view of a PopupMenu is that you have to get it directly from your activity with findViewById(). If you get it from MenuItemCompat.getActionView(), the PopupMenu will raise an exception. I make this clear because I had problems with this and nowhere is stated that you have to get it from there.

我希望这可以帮助别人!

I hope this helps someone!

这篇关于更改Android的PopupMenu的文本颜色不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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