首页 > 解决方案 > 如何正确导入 AndroidX,以便可以在 XML 中使用自动完成功能?

问题描述

我尝试使用此首选项布局

<PreferenceScreen
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <PreferenceCategory
        app:key="display"
        app:title="Display">

    <SwitchPreferenceCompat
        app:key="notifications"
        app:title="Enable message notifications"/>

    </PreferenceCategory>

    <Preference
        app:key="feedback"
        app:title="Send feedback"
        app:summary="Report technical issues or suggest new features"/>

</PreferenceScreen>

但是关闭的 PreferenceCategory 和 PreferenceScreen 在编辑器中被删除,它说 android.pref... 已弃用!

当我用 androidx 指定完整路径时......错误消失了,但我想使用它们而不必指定完整路径......

dependencies {

    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.preference:preference:1.1.0-rc01'

    implementation 'androidx.legacy:legacy-preference-v14:1.0.0'

    implementation 'androidx.appcompat:appcompat:1.0.2'

    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    implementation 'com.google.android.material:material:1.0.0'

    testImplementation 'junit:junit:4.12'

    androidTestImplementation 'androidx.test:runner:1.2.0'

    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

更新:删除 .idea 文件夹并执行“无效缓存并重新启动”并没有解决它...

标签: androidxmlautocompleteandroidx

解决方案


推荐阅读