I did create preferences XML then I see the PreferenceScreen
has been deprecated by API 29. What is the replacement?
And you can see depreciation message here:
Use the AndroidX Preference Library for consistent behavior across all devices. For more information on using the AndroidX Preference Library see Settings. Represents a top-level Preference that is the root of a Preference hierarchy. A PreferenceActivity points to an instance of this class to show the preferences.
It's still possible to customise the appearance of a Preference item though. In your XML you have to declare the root element as android:id="@android:id/widget_frame , and then declare TextView as android:title and android:summary . You can then declare other elements you want to appear in the layout.
A PreferenceFragmentCompat is the entry point to using the Preference library. This Fragment displays a hierarchy of Preference objects to the user. It also handles persisting values to the device.
It's deprecated in API level 29 base on Google Document and also by the Google recommendation you should use AndroidX Preference Library instead.
You can check AndroidX Preference guide in this link
If you still have the problem after Migrate to Androidx
you can use
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> </androidx.preference.PreferenceScreen>
instead of
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"> </PreferenceScreen>
It's not necessary but you can add this implementation into your Gradle too.
implementation 'androidx.preference:preference:X.Y.Z'
As described in the official doc:
This class was deprecated in API level 29.
Use the AndroidX Preference Library for consistent behavior across all devices
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With