2016-02-26 81 views
0

樣本偏好屏幕我創建:添加腳註分隔在PreferenceFragment

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> 
    <PreferenceCategory android:title="GROUP1"> 
     <Preference 
      android:title="ITEM1" 
      android:key="ITEM1"> 
     </Preference> 
    </PreferenceCategory> 
    <PreferenceCategory android:title="GROUP2"> 
     <Preference 
      android:title="ITEM2" 
      android:key="ITEM2"> 
     </Preference> 
    </PreferenceCategory> 
</PreferenceScreen> 

我希望每個PreferenceCategory後添加腳註分隔。

回答

0

您可以根據自己的喜好類別創建一個自定義佈局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical"> 

<View 
    android:layout_width="match_parent" 
    android:layout_height="1dp" 
    android:background="#808080" /> 

<TextView 
    android:id="@android:id/title" 
    style="?android:attr/listSeparatorTextViewStyle" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_vertical" /> 
</LinearLayout> 

然後在你的喜好XML文件,引用佈局:

<PreferenceCategory 
android:title="Preference Title" 
android:layout="@layout/<the layout name above>"> 

這將以上職稱的分隔,所以你會爲所有類別做第一個類別。您可能想要調整分隔線的間距。