[英]Material divider after category preference
我試圖用物質主題來塑造我的喜好,而且幾乎就在那里。
我導入了以下內容:
compile 'com.android.support:preference-v7:25.1.0'
compile 'com.android.support:preference-v14:25.1.0'
然后在我的主應用主題中設置首選項主題:
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
我的偏好屏幕看起來很不錯。 我唯一的問題是類別沒有空間或視覺分離,使得所有偏好看起來非常混亂。
材質設計文檔顯示的分隔符看起來像頂部和底部陰影(設備類別上方的IE):
幾個問題:
android提供這個嗎? 如果有,那么有更新的appcompat主題嗎? 或者其他我做錯了什么?
如果android尚未在材質首選項主題中提供此分隔符,那么有人創建了它嗎? 我看到了這一點,他創建了一個帶有自定義布局的新類別,PreferenceFragment中的類別之間的Divider 。 但我不完全確定如何創造所需的效果。
另一個答案很好,稍稍編輯它,以防你只是不理解drawable。
XML /的preferences.xml
<PreferenceCategory
android:layout="@layout/divider"
android:title="Category2">
<Preference
android:title="Test1"
android:summary="Summary1"/>
</PreferenceCategory>
布局/ divider.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="10dp"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="@drawable/shadow"/>
</LinearLayout>
繪制/ shadow.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#1F000000"
android:endColor="@android:color/transparent"
android:angle="90" />
</shape>
如果你仔細觀察截圖,你會注意到你想要的分隔效果在頂部和底部有一個陰影,但不是在中間。 因此,對於分隔符,以下XML應該可以工作: -
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="10dp"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="@drawable/shadow_bottom"/>
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="@drawable/shadow_top"/>
</LinearLayout>
現在,對於PreferenceScreen
,要顯示分隔符,您所要做的就是包含一個空的PreferenceCategory
並將android:layout
設置為上述XML。 像android:layout="@layout/divider_layout"
。 通過“空”偏好類別,我的意思是偏好類別不應該有Preference
兒童。
所以,你的PreferenceScreen
應該是這樣的: -
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="Category_First">
<Preference
android:title="prefA"/>
</PreferenceCategory>
<PreferenceCategory
android:layout="@layout/divider_layout">
</PreferenceCategory>
<PreferenceCategory
android:title="Category_Second">
<Preference
android:title="prefB"/>
</PreferenceCategory>
</PreferenceScreen>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.