我有一些PreferenceCheckBoxes的PreferenceScreen。我想更改標題和摘要的textColor和textSize,並勾選和取消選中CheckBox的圖像。所以我使用android:layout
來改變這個屬性。帶自己的佈局的CheckBoxPreference
我ChceckBoxPreference:
<CheckBoxPreference
android:layout="@layout/preference_checkbox"
android:key="temp"
android:title="@string/title"
android:summary="@string/summary"
android:defaultValue="true"
/>
當我使用android:widgetLayout
它看起來很奇怪。這是我preference_checkbox.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
>
<TextView
android:id="@+android:id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/gray"
android:textSize="20sp"
/>
<TextView
android:id="@+android:id/summary"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/gray"
android:textSize="14sp"
/>
</LinearLayout>
<CheckBox
android:id="@+android:id/checkbox"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
/>
</RelativeLayout>
冠軍ID @+android:id/title
和總結與@+android:id/summary
都呈現正確的價值觀。但是,儘管缺省值和編號爲@+android:id/checkbox
的複選框無法正常工作。它沒有顯示正確的值,我無法更改保存在首選項中的值。 不使用任何佈局,我可以通過觸摸整個CheckBoxPreference來更改複選框的值。但現在(使用我的佈局),只需觸摸此複選框即可更改複選框的值。 如何以正確的方式爲所有功能製作CheckBoxPreference的佈局?
見http://stackoverflow.com/questions/3569412/customize-check-box-preference,設置可點擊和可聚焦爲false,您的複選框 – devisnik
@devisnik的OP正在談論改變整個佈局背後的偏好,你指出的解決方案只是關於複選框 –
devisnik的答案應該是正確的。需要這些設置來改變偏好值。 – user1608385