【发布时间】:2019-05-31 01:26:25
【问题描述】:
我正在尝试使用新的 androidx 首选项库,但 Android Studio 根本无法在 xml 中识别它。在我的res/xml/setting_prefs.xml,我有
<?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>
虽然这在运行时运行良好,但 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 库)。请注意,androidx 首选项类正在 java 代码中被识别,没有任何问题。
【问题讨论】:
-
提供状态更新:- 不,问题没有解决。我放弃了那个项目,因为它只是一个测试项目,从来没有遇到过类似的问题。所以,如果有人弄清楚了或者这个问题在以后的版本中得到了解决,请留下答案。它可能对某人有所帮助
标签: android xml android-preferences androidx