I am trying to use the new androidx preference library but Android Studio simply does not recognize it in the xml. In my res/xml/setting_prefs.xml
, I have
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:key="@string/settings">
<androidx.preference.SwitchPreference android:key="test"
android:title="test"/>
<androidx.preference.SeekBarPreference
android:title="Stopwatch frequency"
android:summary="The time (in ms) between each update of the stopwatch"
android:defaultValue="100"
android:min="50"
android:max="200"/>
</androidx.preference.PreferenceScreen>
Although this works fine when run, android studio simply does not recognize anything and does not provide autocomplete suggestions.
I have added the relevant dependencies in the build.gradle
file:
implementation 'androidx.legacy:legacy-preference-v14:1.0.0'
implementation 'androidx.preference:preference:1.1.0-alpha02'
and android studio is set to use androidx with
android.enableJetifier=true
android.useAndroidX=true
(Note that this is a completely new Androidx project and not an old project I migrated. I used migrate to androidx immediately after starting a new project)
I am using Android Studio 3.2.1 and have already tried common solutions like invalidate cache+restart, removing the .idea
folder, removing the dependencies and adding them again (and even changing the version), deleting the xml file and creating a new one and even trying to run a clean gradle build. The only things it recognizes or provides suggestion on are the android.preference.PreferenceScreen
class and some other classes from the default (non androidx library). Note that the androidx preference class is being recognized in the java code without any trouble.