Android - ActionBarSherlock - 在菜单中设置文本的文本颜色

时间:2012-05-25 06:18:50

标签: android menu android-actionbar actionbarsherlock submenu

我想将文字的白色更改为橙​​色。

这是一个例子。

ActionBarSherlock

2 个答案:

答案 0 :(得分:3)

这可以通过为操作栏设置一些样式来完成。这篇博客文章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>

答案 1 :(得分:1)

您可以使用MenuItem代替SpannableString轻松更改String文字的颜色。

@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);
}
相关问题