2012-08-03 92 views
6

就拿這個小preference.xml文件:android:首選項xml中的visibility屬性不起作用? (Android 2.3的)

<?xml version="1.0" encoding="utf-8"?> 
<PreferenceScreen android:title="@string/sig_title" xmlns:android="http://schemas.android.com/apk/res/android"> 
<ListPreference android:entries="@array/text_display_entries" android:title="@string/sig_style" android:key="text_style" android:entryValues="@array/text_display_values" /> 
<CheckBoxPreference android:title="@string/custom_font" android:key="tweaks_text" /> 
<CheckBoxPreference android:title="@string/col_random" android:key="random_color_pref" /> 
<CheckBoxPreference android:visibility="invisible" android:enabled="false" android:title="@string/sig_show" android:key="show_sig" /> 
</PreferenceScreen> 

屬性的android:知名度= 「隱形」 在過去的複選框不工作;這個屬性(或者就此而言)不適用於偏好?

我沒有在代碼中弄亂它的可見性,只是好奇爲什麼這不起作用。

回答

10

android:visibility用於顯示和隱藏View s,但它不適用於PreferencedocumentationPreference列出了可用的XML屬性,但沒有一個是你想要的。

,但是,可能以編程方式添加和刪除PreferenceScreen的偏好。

0

您必須使用setVisible方法來更改可見性。

首先,初始化複選框首選項。

CheckBoxPreference showSigPreference = (CheckBoxPreference) findPreference("show_sig"); 

然後

// Show the check box preference 
showSigPreference.setVisible(true); 

// Hide the check box preference 
showSigPreference.setVisible(false);