how to remove this warning - "Element SwitchPreferenceCompat is not allowed here"?
Try to replace
android.support.v7.preference.PreferenceScreen in the root tag of your preference XML file (the pref_visualizer.xml in this case).
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 to update the parent tag to v7). however the instructions and recommendation in the android developer site (developer.android.com/guide/topics/ui/settings) 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.