gpt4 book ai didi

Android Studio 无法识别 xml 中的 androidx 首选项库

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:14:10 26 4
gpt4 key购买 nike

我正在尝试使用新的 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 库)中的一些其他类。请注意,在 java 代码中可以毫无问题地识别 androidx 首选项类。

最佳答案

只需使用 <PreferenceScreen>标记而不是 androidx.preference.PreferenceScreen .

这是一个bug,希望尽快解决。确保<PreferenceScreen>没有出现任何问题,只需在完成使用 xml 文件后重命名即可。

关于Android Studio 无法识别 xml 中的 androidx 首选项库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54039525/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com