小编Yas*_*n99的帖子

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

我正在尝试使用新的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>
Run Code Online (Sandbox Code Playgroud)

尽管这在运行时效果很好,但android studio根本无法识别任何内容,也不提供自动完成建议。

我在build.gradle文件中添加了相关的依赖项:

implementation 'androidx.legacy:legacy-preference-v14:1.0.0'
implementation 'androidx.preference:preference:1.1.0-alpha02'
Run Code Online (Sandbox Code Playgroud)

并且android studio设置为将androidx与

android.enableJetifier=true
android.useAndroidX=true
Run Code Online (Sandbox Code Playgroud)

(请注意,这是一个全新的Androidx项目,而不是我迁移的旧项目。启动新项目后,我立即使用了迁移到androidx的功能)

我正在使用Android Studio 3.2.1,并且已经尝试了一些常见的解决方案,例如使缓存+重新启动无效,删除.idea文件夹,删除依赖项并再次添加它们(甚至更改版本),删除xml文件并创建一个新的甚至尝试运行干净的gradle版本。它唯一可以识别或提供建议的是android.preference.PreferenceScreen该类和默认(非androidx库)中的其他一些类。请注意,在Java代码中可以毫无问题地识别androidx首选项类。

xml android android-preferences androidx

8
推荐指数
1
解决办法
945
查看次数

无法使用导航组件清除所有片段的返回堆栈

我正在使用 Android 导航组件并面临一个奇怪的问题。无论我尝试什么,我都无法清除向上按钮的返回堆栈。

我的导航图如下所示:

导航图

让我们以 LoginFragment 为例,

<fragment
    android:id="@+id/loginFragment"
    android:name="com.yashovardhan99.firebaselogin.LoginFragment"
    android:label="Login"
    tools:layout="@layout/fragment_login" >
    <action
        android:id="@+id/action_loginFragment_to_welcomeFragment"
        app:destination="@id/welcomeFragment"
        app:popUpTo="@+id/nav_graph"
        app:popUpToInclusive="true" />
</fragment>
Run Code Online (Sandbox Code Playgroud)

要导航的 Java 代码是:

navController.navigate(
        LoginFragmentDirections.actionLoginFragmentToWelcomeFragment());
Run Code Online (Sandbox Code Playgroud)

我已将 PopUpTo 设置为图形 ID,并将 Inclusive 设置为 true。移动到 WelcomeFragment 时,这应该清除返回堆栈。但是,WelcomeFragment 仍然在操作栏上显示向上按钮,按下它会将我带回 PreLoginFragment(这是图表的主目的地)。奇怪的是,按后退按钮让我按预期退出了应用程序。

android android-fragments android-jetpack android-architecture-navigation

5
推荐指数
1
解决办法
441
查看次数