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

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

The "SwitchPreferenceCompat" tag belongs to the library. so you need to match the libraries of the parent "PreferenceScreen" tag and the "SwitchPreference" tag (@f0rrest suggested to update the parent tag to v7). however the instructions and recommendation in the android developer site ( is to use the AndroidX Preference Library. therefore i suggest to migrate the project to AndroidX and use "androidx.preference.PreferenceScreen" for the parent tag.