android - 导航预览在 Android Studio 3.2 预览版中不可用

标签 android android-architecture-components android-architecture-navigation android-studio-3.2

我有兴趣尝试 Android Studio 中显示的导航图。但是我导入 google sample 后预览不可用

我使用的是 Android Studio 3.2 Preview Canary 16

enter image description here

<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:startDestination="@+id/launcher_home">

    <fragment
        android:id="@+id/launcher_home"
        android:name="com.android.samples.arch.componentsbasicsample.StartFragment"
        android:label="Home">

        <action
            android:id="@+id/end_action"
            app:destination="@id/end_dest" />

    </fragment>

    <fragment
        android:id="@+id/end_dest"
        android:name="com.android.samples.arch.componentsbasicsample.EndFragment"
        android:label="End"
        >

    </fragment>
</navigation>

2018 年 10 月 6 日更新:

即使我重新构建项目也无法正常工作。但如果添加新屏幕,它会在预览模式下显示新屏幕

enter image description here

最佳答案

您应该在导航编辑器(导航图的 xml 文件)中单击“文本”选项卡,然后添加:

tools:layout="@layout/layout_name"

在目标元素内。

应该是这样的:

<fragment
    android:id="@+id/someFragment"
    android:name="com.freesoulapps.navigationtest.fragments.SomeFragment"
    android:label="Some Fragment"
    tools:layout="@layout/layout_name">
</fragment>

关于android - 导航预览在 Android Studio 3.2 预览版中不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50776284/

相关文章:

java - 使用缓冲区的 ReadLine() ?

android - 如何在 Jetpack 中使用导航启动第二个 Activity

android - 在不使用 Room 的情况下使用 LiveData 和 ViewModel

android - 检索removeGhost方法失败

android - 导航架构组件 - 新资源对话框没有导航图的导航资源类型

javascript - Flash 在 Android 浏览器解决方法中始终位于最前面?

Android:如果应用程序被卸载/降级,则不会删除应用程序私有(private)文件夹

android - 在 TimePicker 中使用键盘输入需要在 "Enter"之前按 "OK",否则值将被丢弃

android - 屏幕旋转时的 ViewModel 更新

android-architecture-navigation - 您如何使用导航 UI 将参数传递给从抽屉导航调用的片段?