Ric*_*rdP 22 android divider android-layout android-spinner
我使用具有分隔符的listviews和expandviews,我可以设置它们但是在spinner上看起来它们之间没有分隔符.
谁有想法如何解决这个问题?
X09*_*X09 20
这对我有用:
<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>
Run Code Online (Sandbox Code Playgroud)
使用它的优点是它不会消除悬停时的涟漪效应.
Tal*_*awk 14
我设法为这个问题找到了更合适的解决方案(不包括单项布局中的分隔符).
您要做的是在活动的主题中定义
<item name="android:dropDownListViewStyle">@style/App.Style.Spinner</item>
Run Code Online (Sandbox Code Playgroud)
然后用它创建合适的样式
<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>
Run Code Online (Sandbox Code Playgroud)
根据@Talihawk的回答,我让它仅适用于特定的微调器.不是设置活动主题,而是直接为微调器视图设置主题:
<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>
Run Code Online (Sandbox Code Playgroud)
和
<android.support.v7.widget.AppCompatSpinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/MatchSpinnerTheme"/>
Run Code Online (Sandbox Code Playgroud)
对于有同样问题的人,我几乎放弃了,我知道了如何获得分隔线。
我在每个项目的自定义布局底部添加了分隔线
<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29108 次 |
| 最近记录: |