[英]Lollipop actionbar menu item text is black instead of white?
Here is how I add items to the menu in action bar: 这是我向操作栏中的菜单添加项目的方式:
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
TypefaceSpan actionBarTypeFace = new CustomTypefaceSpan("", a.bumpFont);
SpannableString s = new SpannableString("Done"));
s.setSpan(actionBarTypeFace, 0, s.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
MenuItem item = menu.add(21, 142, 0, s);
item.setTitle(BaseActivity.isLGDevice() ? "Done") : s);
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
// fix android formatted title bug
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2 && item.getTitleCondensed() != null) {
item.setTitleCondensed("Done"));
}
}
Item font is usually white, but its black on Lollipop. 项目字体通常为白色,但在棒棒糖上为黑色。 Anyone know what is the cause of that and how can I fix it?
有人知道是什么原因造成的,如何解决?
Anyone know what is the cause of that...
谁知道是什么原因...
Most likely it's caused by the fact the app themes on pre-Lollipop devices and on Lollipop devices have different menu items' text colors. 很有可能是由于Lollipop之前的设备和Lollipop设备上的应用程序主题具有不同的菜单项文本颜色的事实造成的。
... and how can I fix it?
...以及如何解决?
I've changed the color of menu items' text color in my app in the following way: 我已经通过以下方式在应用中更改了菜单项的文本颜色:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:itemTextAppearance">@style/MenuTextAppearance</item>
</style>
<style name="MenuTextAppearance" parent="@android:style/TextAppearance.Widget.IconMenu.Item">
<item name="android:textColor">#FFF</item>
</style>
Basically, all you need to do is make your own MenuTextApperance
style and set it in the app's theme "android:itemTextAppearance"
element. 基本上,您所需要做的就是制作自己的
MenuTextApperance
样式并将其设置在应用程序的主题"android:itemTextAppearance"
元素中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.