简体   繁体   English

棒棒糖动作栏菜单项文本是黑色而不是白色?

[英]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.

相关问题 为什么在ActionBar中创建导航下拉菜单时,文本是黑色而不是白色? - Why is the text black instead of white when I create a navigation dropdown in an ActionBar? 如果 actionBar/Toolbar 为白色,则菜单项上没有波纹 - No ripple on menu item if actionBar/Toolbar is white 在项目菜单操作栏上绘制文本 - draw text on item menu actionbar ActionBar不剪切菜单项文本 - ActionBar Not Clipping Menu Item Text 在app启动时看到的白色屏幕和操作栏而不是黑屏 - White screen and actionbar seen on app startup instead of black screen ListPreference 条目的文本颜色是白色而不是黑色 - Text color of ListPreference entries is white instead of black Android:工具栏文字显示为黑色而不是白色 - Android: Toolbar text is coming as black instead of white Android DialogFragment 文本颜色是白色而不是黑色 - Android DialogFragment text color is white instead of black 我的应用程序在nexus 4棒棒糖设备上不显示文本颜色,但黑白除外 - My App not showing text colors except black and white on nexus 4 lollipop device 如何更改Lollipop之前和Lollipop版本的工具栏菜单项文本颜色 - How to change toolbar menu item text color for pre Lollipop and Lollipop versions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM