I using listviews and expandedviews that has dividers and I can set them but on spinner its looks like it is no divider between items.
Someone that has a idea of how to fix this?
This worked for me:
<style name="SpinnerStyle" parent="Widget.AppCompat.ListView.DropDown">
<item name="android:divider">#d1d1d1</item>
<item name="android:dividerHeight">0.5dp</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:dropDownListViewStyle">@style/SpinnerStyle</item>
The advantage of using this is that it doesn't remove the ripple effect on hover.
I managed to find a more proper solution for this issue (without including the divider in the single item layout).
What you have to do is define in your activity's theme
<item name="android:dropDownListViewStyle">@style/App.Style.Spinner</item>
and then create the proper style with
<style name="App.Style.Spinner" parent="@style/Widget.Sherlock.Light.ListView.DropDown">
<item name="android:dividerHeight">10dip</item>
<item name="android:divider">@drawable/mydivider</item>
</style>
Based on @Talihawk answer, I made it work for specific spinner only. Instead of setting your activity theme, set the theme directly for the spinner view:
<style name="MatchSpinnerStyle" parent="android:style/Widget.ListView.DropDown">
<item name="android:divider">#123456</item>
<item name="android:dividerHeight">1dp</item>
</style>
<style name="MatchSpinnerTheme" parent="AppTheme">
<item name="android:dropDownListViewStyle">@style/MatchSpinnerStyle</item>
</style>
and
<android.support.v7.widget.AppCompatSpinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/MatchSpinnerTheme"/>
For people with same problem i after almost gived up i got an idea of how to get the divider.
I added the divider line at the bottom of my custom layout for each item
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/RelativeLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" style="@style/ListItem2">
<TextView android:id="@+id/Text" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"
style="@style/SpinnerView_Text" android:paddingLeft="10dip" />
<ImageView android:id="@+id/icon" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/arrowright"
android:layout_alignParentRight="true" android:layout_centerInParent="true"
android:layout_marginRight="20dip" />
</RelativeLayout>
<ImageView android:id="@+id/Divider1" android:layout_width="fill_parent"
android:layout_height="1dip" style="@style/Divider"></ImageView>
来源:https://stackoverflow.com/questions/4569751/how-to-show-divider-between-spinner-items