我正在尝试使用新的androidx首选项库,但Android Studio根本无法在xml中识别它。在我的res/xml/setting_prefs.xml,我有
xmlns:app="http://schemas.android.com/apk/res-auto"
android:key="@string/settings">
android:title="test"/>
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"/>
尽管这在运行时效果很好,但android studio根本无法识别任何内容,也不提供自动完成建议。
我在build.gradle文件中添加了相关的依赖项:
implementation 'androidx.legacy:legacy-preference-v14:1.0.0'
implementation 'androidx.preference:preference:1.1.0-alpha02'
并且android studio设置为将androidx与
android.enableJetifier=true
android.useAndroidX=true
(请注意,这是一个全新的Androidx项目,而不是我迁移的旧项目。启动新项目后,我立即使用了迁移到androidx的功能)
我正在使用Android Studio 3.2.1,并且已经尝试了一些常见的解决方案,例如使缓存+重新启动无效,删除.idea文件夹,删除依赖项并再次添加它们(甚至更改版本),删除xml文件并创建一个新的甚至尝试运行干净的gradle版本。它唯一可以识别或提供建议的是android.preference.PreferenceScreen该类和默认(非androidx库)中的其他一些类。请注意,在Java代码中可以毫无问题地识别androidx首选项类。





