使用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知道如何放置标题文本或图标图像。
我希望这有助于!