Change title text color and size of android action bar

I am developing an Android application and in my application I am using Sherlock's action bar. I am using some kind of menu in my action bar.

<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@+id/card_menu"
      android:title="C123" 
      android:showAsAction="always">
    <menu>
        <item android:id="@+id/C0"
              android:title="C0"/>
        <item android:id="@+id/c1"
              android:title="c1" />
        <item android:id="@+id/c2"
              android:title="c2" />
    </menu>
    </item>
<item android:id="@+id/notification"
  android:title="Notifications"
  android:showAsAction="always"
  android:actionLayout="@layout/notification_icon"
  android:icon="@drawable/notification"
  />
<item android:id="@+id/filter"
  android:icon="@drawable/filter"
  android:title="Filter" 
  android:showAsAction="always"
  />

</menu>

      

and I will display this menu in my activity like this.

inflater.inflate(R.menu.menu_type2, menu);

      

now what i want to do is change the title color of my menu item (c123). I can change the color of the submenu from the style, but was unable to change this element text. I tried it in the following way.

// this change my sunbmenu text color but I am not able to change color of item text(c123)
<item name="android:dropDownListViewStyle">@style/MyPopupMenu</item>
<item name="dropDownListViewStyle">@style/MyPopupMenu</item>

<style name="MyPopupMenu" parent="Widget.Sherlock.ListPopupWindow">
 <item name="android:textAppearance">@style/TextAppearance.Sherlock.Widget.PopupMenu</item>
 <item name="android:dropDownSelector">@color/white</item>
 <item name="android:dividerHeight">@dimen/divider_height</item>
 <item name="android:divider">@color/maroon</item>

</style>

<style name="TextAppearance.Sherlock.Widget.PopupMenu" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Menu">
 <item name="android:textColor">@color/white</item>
</style>  

      

I want to change this style change style and text color of the menu style as well as the background of this. How to do it. Need help .. Thank you ..

+3


source to share


1 answer


You can easily change the color of the text MenuItem

using SpannableString

instead 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);
}

      

+2


source







All Articles