使用PreferenceScreen
時,您無權訪問這些xml屬性。但是你可以做的是這樣的屬性添加到它:
android:layout="@layout/header_setting"
然後創建一個名爲在這個例子中的XML佈局文件「header_settings」你可以改變大小和填充爲正常。但是,將PreferenceScreen知道標題的位置或圖標的位置應用到元素中。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:padding="0dp"
android:layout_height="match_parent">
<ImageView
android:id="@+android:id/icon"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:layout_width="40dp"
android:layout_height="40dp" />
<TextView android:id="@+android:id/title"
android:layout_marginLeft="80dp"
android:textColor="#000"
android:layout_marginTop="23dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"/>
</LinearLayout>
喏,這就是對PreferenceScreen應該怎麼看起來像一個例子:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:layout="@layout/pref_screen">
<PreferenceCategory>
<PreferenceScreen
android:icon="@drawable/setting_star"
android:layout="@layout/header_setting"
android:title="Upgrade to Pro!">
</PreferenceScreen>
</PreferenceCategory>
</PreferenceScreen>
注意如何只能訪問屬性:標題,摘要和圖標。佈局屬性可讓您將其自定義爲任何您想要執行的操作。在XML中,您必須保持ID相同,因爲PreferenceScreen知道如何放置標題文本或圖標圖像。
我希望這有助於!