Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android spinner divider color

Tags:

android

I have a spinner styled like this

<style name="OptionsSpinner" parent="android:Widget.Spinner">
    <item name="android:background">@drawable/spinner_background</item>
    <item name="android:spinnerMode">dropdown</item>
    <item name="android:dropDownListViewStyle">@style/SpinnerDropdown</item>
</style>

<style name="SpinnerDropdown">
    <item name="android:divider">#ff0000</item>
</style>

but the style SpinnerDropDown doesn't have any effect, the divider is grey or whatever the default is. How do I style the dividers in a spinner?

like image 860
L84 Avatar asked Sep 05 '13 16:09

L84


1 Answers

You are using this style directly in the style property of your Spinner widget? If so, that's why it's not working. You should style the divider using the theme of your application.

To style the divider, do the following:

In your application theme you should have the item android:dropDownListViewStyle:

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

And, the style of the divider (mySpinnerStyle) is defined in:

<style name="mySpinnerStyle" parent="android:Widget.ListView.DropDown">
    <item name="android:divider">#00ff00</item>
    <item name="android:dividerHeight">1dp</item>
</style>

Now you have a green divider on your Spinner :)

like image 74
jademcosta Avatar answered Oct 16 '22 07:10

jademcosta