Android - ActionBarSherlock - 在菜单中设置文本的文本颜色
答
这可以通过设置一些样式你的动作条来完成。这是在这篇博文中解释http://android-developers.blogspot.com.au/2011/04/customizing-action-bar.html
你需要为你的应用程序设置你的风格。
<style name="MyTheme" parent="android:style/Theme.Holo.Light">
<item name="android:dropDownListViewStyle">@style/MyDropDownListView</item>
</style>
然后,您可以使用自己的文本颜色指定此样式。
<!-- style the items within the overflow menu -->
<style name="MyDropDownListView" parent="android:style/Widget.Holo.ListView.DropDown">
<!-- This is the orange text color -->
<item name="android:textColor">#CC3232</item>
</style>
答
这没有改变文字颜色,只有Backgorund颜色
答
您可以轻松地通过使用SpannableString
代替String
改变MenuItem
文本的颜色。
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.your_menu, menu);
int positionOfMenuItem = 0; // or whatever...
MenuItem item = menu.getItem(positionOfMenuItem);
SpannableString s = new SpannableString("My red MenuItem");
s.setSpan(new ForegroundColorSpan(Color.RED), 0, s.length(), 0);
item.setTitle(s);
}
那么这实际上不适合我。这里的DropDown Item只有后台选择器。 – redestructa
适合我!我实际上是在Xamarin Android中开发的,我一直在寻找这个解决方案。经过无数谷歌搜索,我终于绊倒了这一点,并尝试它,它的工作就像一个魅力。你不知道这个子菜单最终会变成蓝色的哈哈。 – TeamChillshot