Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the 'little triangle color' in action bar NAVIGATION_MODE_LIST

After I set action bar to NAVIGATION_MODE_LIST

getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

and then set an adapter for it.

The list show up as expected, but I need to change the 'little triangle' color of the list as the default color is very close to my background color.

Is it possible to do this, if so, how can I do it?

like image 564
Pongpat Avatar asked Oct 13 '12 00:10

Pongpat


1 Answers

The little triangle you want to change is in the background of a Spinner widget in ActionBar. The background is a state list drawable. Items of the state list drawable are 9-patch drawables like this one (this particular one is the hdpi version for default state for Holo light theme):

enter image description here

To change the color of the triangle you have to change few sets of these 9-patch drawables - one drawable for each dpi and combination of states. You'll also need custom state list drawable to be as as the background of the Spinner widget.

To change the widget background you have to adjust the theme. If you are using ActionBarSherlock (ABS) change actionDropDownStyle item and for native ActionBar change android:actionDropDownStyle item (even if you use ABS native ActionBar is used for devices running Android 4.0 and higher).

The theme should be something like:

<style name="MyTheme" parent="SomeParentStyle>
    <item name="actionDropDownStyle">@style/MyActionBarSpinnerStyle</item><!-- if you use ABS -->
    <item name="android:actionDropDownStyle">@style/MyActionBarSpinnerStyle</item>
</style>

And MyActionBarSpinnerStyle should be something like:

<style name="MyActionBarSpinnerStyle" parent="@style/MyDropDownActionBarStyle">
    <item name="android:background">@drawable/my_custom_state_list_drawable</item>
</style>

Where instead of MyDropDownActionBarStyle there should be something like Widget.Sherlock.Light.Spinner.DropDown.ActionBar if you use ABS or Widget.Holo.Light.Spinner.DropDown.ActionBar if you target only native ActionBar.

like image 95
Tomik Avatar answered Oct 18 '22 06:10

Tomik