Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove this warning - "Element SwitchPreferenceCompat is not allowed here"?

Tags:

android

xml

In an Android project inside res/xml/ file name pref_visualizer.xml

<?xml version="1.0" encoding="utf-8"?>

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

    <SwitchPreferenceCompat
        android:defaultValue="@bool/pref_show_bass_default"
        android:key="@string/pref_show_bass_key"
        android:summaryOff="@string/pref_show_false"
        android:summaryOn="@string/pref_show_true"
        android:title="@string/pref_show_bass_label" />
    <SwitchPreferenceCompat
        android:key="@string/pref_show_mid_key"
        android:title="@string/pref_show_mid_label"
        android:summaryOff="@string/pref_show_false"
        android:summaryOn="@string/pref_show_true"
        android:defaultValue="@bool/pref_show_bass_default" />
    <SwitchPreferenceCompat
        android:key="@string/pref_show_treble_key"
        android:title="@string/pref_show_treble_label"
        android:summaryOff="@string/pref_show_false"
        android:summaryOn="@string/pref_show_true"
        android:defaultValue="@bool/pref_show_bass_default" />

</PreferenceScreen>

The SwitchPreferenceCompat text is highlighted and says it cant be allowed here.How to fix this warning. The app runs without any problem. But still I would like to know How to fix this issue.

like image 613
Kundan Avatar asked Jun 30 '17 09:06

Kundan


2 Answers

Try to replace PreferenceScreen with android.support.v7.preference.PreferenceScreen in the root tag of your preference XML file (the pref_visualizer.xml in this case).

like image 71
f0rrest Avatar answered Nov 02 '22 13:11

f0rrest


Your PreferenceScreen's layout cannot be in res/layout/ they have to be in res/xml/

like image 42
JackWu Avatar answered Nov 02 '22 14:11

JackWu