![](/img/trans.png)
[英]error retrieving parent for item theme.appcompat.light.darkactionbar
[英]How to change the text color of a menu item in Theme.AppCompat.Light.DarkActionBar theme?
我有黑色背景,白色字母。
有任何想法吗? 谢谢。
<style name="PacerTheme"
parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:itemBackground">@android:color/black</item>
<item name="android:itemTextAppearance">@style/myCustomMenuTextApearance</item>
</style>
<style name="myCustomMenuTextApearance" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
<item name="android:textColor">@android:color/white</item>
</style>
正常:
单击菜单按钮,然后显示:
修改样式如下:
<style name="PacerTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:itemTextAppearance">@style/myCustomMenuTextApearance</item>
</style>
<style name="myCustomMenuTextApearance" parent="@android:style/TextAppearance.Widget.IconMenu.Item">
<item name="android:textColor">@android:color/white</item>
</style>
对于“ myCustomMenuTextApearance”样式,请为父项使用
@android:style/TextAppearance.Widget.IconMenu.Item
代替
@style/Widget.AppCompat.Light.ActionBar.Solid
我找到了解决方法,程序更改了文本颜色,如下所示:
@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;
}
XML如下:
<style name="PacerTheme"
parent="@style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:itemBackground">@android:color/black</item>
</style>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.