如何解决PreferenceFragmentCompat 未显示来自 XML 的所有偏好
我正在我的应用程序上设置 PreferenceScreen
,但 PreferenceFragmentCompat
没有在屏幕上显示所有提到的 XML 首选项。
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:background="?android:attr/colorBackground"
android:clickable="true"
android:focusable="true">
<PreferenceCategory
android:iconSpaceReserved="false"
android:key="app_setting"
android:summary="General account setting for app"
android:title="Account Setting">
<SwitchPreferenceCompat
android:checked="true"
android:defaultValue="true"
android:icon="@drawable/ic_check"
android:key="button"
android:summary="Turn on "
android:switchTextOff="OFF"
android:switchTextOn="ON"
android:title="Updates" />
<Preference
android:fragment="com.reacher.Settings_Fragmets.BackUp_Fragment"
android:icon="@drawable/ic_loop_black_24dp"
android:summary="Reset your account by deleting all data from server and from app excluding users connections"
android:title="Reset Account" />
</PreferenceCategory>
<PreferenceCategory android:title="Notifications">
<SwitchPreferenceCompat
android:defaultValue="true"
android:icon="@drawable/ic_vibration_black_24dp"
android:key="Notification_vibrate"
android:summary="Vibrate when receive new notification"
android:title="Vibrate" />
</PreferenceCategory>
<PreferenceCategory android:title="Privacy & User Setting">
<Preference
android:icon="@drawable/ic_backup_black_24dp"
android:key="bkup"
android:summary="Backup"
android:title="Account">
</Preference>
<Preference
android:key="blocked"
android:summary="People's you block to view your profile and send you message"
android:title="Blocked List">
</Preference>
</PreferenceCategory>
<!--NOT SHOWING ANY PREFERENCE FROM HERE -->
<PreferenceCategory
android:icon="@drawable/ic_phonelink_lock_black_24dp"
android:title="Control">
<ListPreference
android:defaultValue="1"
android:dialogTitle="Post"
android:entries="@array/pref_futurepost_entries"
android:entryValues="@array/pref_futurepost_values"
android:key="futurePot"
android:summary=" next post."
android:title="Future Post">
</ListPreference>
<ListPreference
android:defaultValue="1"
android:dialogTitle="Allow Comments"
android:entries="@array/pref_futurepost_entries"
android:entryValues="@array/pref_futurepost_values"
android:key="Post"
android:title="Post">
</ListPreference>
<CheckBoxPreference
android:defaultValue="true"
android:key="dob"
android:summary="Check"
android:title="chk parent " />
<CheckBoxPreference
android:defaultValue="true"
android:key="email"
android:title="Allow 0 " />
<CheckBoxPreference
android:defaultValue="true"
android:key="distance"
android:title="Allow 1" />
<CheckBoxPreference
android:defaultValue="true"
android:key="status"
android:title="Allow 2 " />
<CheckBoxPreference
android:defaultValue="true"
android:key="directMessage"
android:title="Allow 3" />
</PreferenceCategory>
<PreferenceCategory android:title="Server tester">
<CheckBoxPreference
android:defaultValue="true"
android:key="Email"
android:title="test 0" />
<CheckBoxPreference
android:defaultValue="true"
android:key="Ph"
android:title="test 1" />
<CheckBoxPreference
android:defaultValue="true"
android:key="loc"
android:title="test 2" />
</PreferenceCategory>
<!--NOT SHOWING ANY PREFERENCE TO HERE -->
<PreferenceCategory android:title="Developer(BETA)">
<Preference
android:summary="Develop your plugins and publish it as add-on"
android:title="Register" />
</PreferenceCategory>
</PreferenceScreen>
在 PreferenceFragmentCompat
的 onCreatePreferences
处充气/加载首选项
` @Override
public void onCreatePreferences(Bundle savedInstanceState,String rootKey) {
//Load The preferences from xml
setPreferencesFromresource(R.xml.setting_main,rootKey);
}`
为什么我看不到我的片段上的所有偏好。有什么想法吗?
解决方法
为什么我看不到我的片段上的所有偏好。有什么想法吗?
好吧,看起来不对的一件事是您为根首选项屏幕传递了一些变量 rootKey
...
setPreferencesFromResource(R.xml.setting_main,rootKey);
但是您的布局没有指定键:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:background="?android:attr/colorBackground"
android:clickable="true"
android:focusable="true">
在 XML 中传递 null
或设置相同的字符串 "key"=YOUR_STRING
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。