How can I remove this warning - "SwitchPreferenceCompat is not allowed here"?
In android project inside res / xml / filename 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 cannot be resolved here. How to fix this warning. The app works without any problem. But still I would like to know how to solve this problem.
source to share
The "SwitchPreferenceCompat" tag belongs to the com.android.support:preference-v7:28.0.0 library. so you need to match the libraries of the parent "PreferenceScreen" tag and the "SwitchPreference" tag (@ f0rrest suggested updating the parent tag to v7). however, the instructions and guidelines on the Android developer site (developer.android.com/guide/topics/ui/settings) should use the AndroidX settings library. so I suggest moving the project to AndroidX and using "androidx.preference.PreferenceScreen" for the parent tag.
source to share