Installing a support library for PreferenceFragmentCompat

For anyone using androidx, add this to your dependencies

dependencies {
    
    ...
    implementation 'androidx.preference:preference:{your_version}'
    // example: implementation 'androidx.preference:preference:1.1.1'
}

After adding com.android.support:preference-v7:23.0.1 to your build.gradle file, simply change the line

For AndroidX : androidx.preference:preference:1.0.0

public class SettingsFragment extends PreferenceFragment {

to

public class SettingsFragment extends PreferenceFragmentCompat {

The error is caused by PreferenceFragment, which extends android.app.Fragment, not android.support.v4.app.Fragment which you need, as you are using support library class.