android:首选项xml中的可见性属性不工作?(安卓2.3)
以这个小preference.xml文件为例:android:首选项xml中的可见性属性不工作?(安卓2.3),android,xml,visibility,preferences,Android,Xml,Visibility,Preferences,以这个小preference.xml文件为例: <?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
<?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:visibility=“invisible”不起作用;此属性(或就此消失)不适用于首选项
我在代码中没有任何东西会影响它的可见性,只是好奇为什么这不起作用。
android:visibility
用于显示和隐藏视图
,但它对于首选项
无效。for首选项
列出了可用的XML属性,但它们都不是您想要的
但是,可以通过编程方式在
首选项屏幕中添加和删除首选项。您必须使用设置可见
方法来更改可见性
首先,初始化复选框首选项
CheckBoxPreference showSigPreference = (CheckBoxPreference) findPreference("show_sig");
然后
我意识到这是一个较老的问题,以前在xml中没有可接受的答案
现在,通过添加AppCompat库,可以直接在xml中执行此操作。请参见中的完整示例,对于AndroidX用户,请将其直接添加到首选项XML中
app:isPreferenceVisible="false"
这对我不起作用,因为setVisible
甚至不是我的CheckBoxPreference
的选项。我知道了,您正在使用androidx。
app:isPreferenceVisible="false"