Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - ActionBarSherlock - Set textcolor of text in menu

I want to change white color of text to orange.

Here is a example.

ActionBarSherlock

like image 366
Paulo Blasterx Avatar asked Oct 08 '22 17:10

Paulo Blasterx


2 Answers

You can change the color of the MenuItem text easily by using SpannableString instead of 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);
}
like image 28
max.mustermann Avatar answered Oct 13 '22 10:10

max.mustermann


This can be done through setting some styles for your action bar. It is explained in this blog post http://android-developers.blogspot.com.au/2011/04/customizing-action-bar.html

You need to set this in your style for you app.

<style name="MyTheme" parent="android:style/Theme.Holo.Light">
     <item name="android:dropDownListViewStyle">@style/MyDropDownListView</item>
</style>

Then you can specify this style with your own text color.

<!-- 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>
like image 69
Cassie Avatar answered Oct 13 '22 12:10

Cassie