我的 xml 文件中有以下首选项:
<?xml version="1.0" encoding="utf-8"?>
<CheckBoxPreference android:title="Alert" android:widgetLayout="@layout/preference_checkbox" android:key="alert"
/>
我想制作自己的自定义复选框,因此正如您在上面看到的,我提供了此首选项“android:widgetLayout”参数,该参数链接到此文件:
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/checkbox"
android:id="@+id/alert">
问题:使用 (widgetLayout) 参数时,它不会保存复选框值。因此,如果我打开首选项复选框就会被选中。然后,如果我取消选中它,并再次打开首选项,则之前的值不会存储,或者不会保留。如果我使用不带参数“android:widgetLayou”的 CheckBoxPreference,则不会出现此问题,在本例中,值已存储。
有什么想法吗?
最佳答案
您可以简单地通过以下方式修复它:
1-将复选框 ID 更改为 android:id="@android:id/checkbox
2- 设置这 3 个属性:
android:focusableInTouchMode="false"
android:clickable="false"
android:focusable="false"
<CheckBox
android:id="@android:id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/checkbox"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false" >
关于java - 不保留 CheckBoxPreference 中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19821979/