Android 如何在屏幕上隐藏首选项
我有一个类Android 如何在屏幕上隐藏首选项,android,Android,我有一个类设置扩展首选项活动在共享首选项ChangeListener上实现。我正在从xml文件加载首选项。但在某些情况下,我需要根据我的应用程序状态完全隐藏其中一个首选项屏幕。我想从屏幕上完全删除该首选项。可能吗?我只需要设置\u帐户和所有其他隐藏 <Preference android:title="Account Settings" android:key="customPref" /> <PreferenceScreen
设置扩展首选项活动在共享首选项ChangeListener上实现。我正在从xml文件加载首选项。但在某些情况下,我需要根据我的应用程序状态完全隐藏其中一个首选项屏幕。我想从屏幕上完全删除该首选项。可能吗?我只需要设置\u帐户
和所有其他隐藏
<Preference
android:title="Account Settings"
android:key="customPref" />
<PreferenceScreen android:title="@string/account_1"
android:key="account">
<EditTextPreference
android:key="username"
android:title="@string/settings_username"
android:singleLine="true" />
<EditTextPreference
android:key="password"
android:title="@string/settings_password"
android:password="true"
android:singleLine="true" />
</PreferenceScreen>
<PreferenceScreen android:title="@string/account_2"
android:key="account1">
<EditTextPreference
android:key="username1"
android:title="@string/settings_username"
android:singleLine="true" />
<EditTextPreference
android:key="password1"
android:title="@string/settings_password"
android:password="true"
android:singleLine="true" />
</PreferenceScreen>
android:title=“@string/settings\u pbxes\u options”>
也许您可以创建第二个首选项xml并加载它。如果您的首选项在首选项类别中,请执行以下操作
XML:
或者你可以做:
myPreferenceScreen.removePreference(myPreference);
查看您是否正在访问在第二种情况下删除的元素。这可能会导致错误当我使用删除首选项时,应用程序会在屏幕打开时崩溃
<PreferenceCategory
android:key="category_foo"
android:title="foo">
<CheckBoxPreference
android:key="checkPref" />
CheckBoxPreference mCheckBoxPref = (CheckBoxPreference) findPreference("checkPref");
PreferenceCategory mCategory = (PreferenceCategory) findPreference("category_foo");
mCategory.removePreference(mCheckBoxPref);
myPreferenceScreen.removePreference(myPreference);