这只适用于spinnermode=“DropDown”…对于对话模式,分隔符必须为
added during runtime via an adapter
(引用的示例也使用下拉列表,但在实现它并将模式更改为对话框后,分隔符仍在显示)。
只需尝试将此添加到
styles.xml
文件在
values
资源目录:
<style name="SpinnerStyle" parent="Widget.AppCompat.ListView.DropDown">
<item name="android:divider">#0000ff</item>
<item name="android:dividerHeight">0.5dp</item>
</style>
<style name="SpinnerTheme" parent="AppTheme">
<item name="android:dropDownListViewStyle">@style/SpinnerStyle</item>
</style>
然后,您可以将一个额外的子节点添加到
style
该文件中已存在的标记(将对所有微调器应用样式):
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:dropDownListViewStyle">@style/SpinnerStyle</item>
</style>
或者…您只需将该样式添加到片段XML中的特定spinner标记中(这将仅将该样式应用于该spinner):
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dropdown"
android:background="@drawable/spinner"
android:theme="@style/SpinnerTheme">
</Spinner>