java - Android中的 "Top-level destination"是什么?

标签 java android android-studio android-navigation-bar

我正在使用 Java 在 Android Studio 中工作。我想实现一个抽屉导航(那些从左到右滑动的抽屉),汉堡图标始终位于顶部。但存在一些“顶级目的地”问题,如果没有这个问题,汉堡图标就不会显示。我发现的解决方案之一是将该 Activity 作为我的启动器 Activity ,但我不希望这样做。

有人可以向我解释一下这个“顶级目的地”短语的含义以及解决我的抽屉导航问题的可能解决方法!!

这是我的导航布局

<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:id="@+id/drawer_layout"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:visibility="visible"
    tools:context=".Main_Screen"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <com.google.android.material.navigation.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:id="@+id/nav_view"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:menu="@menu/drawer_menu"
        app:headerLayout="@layout/drawer_header"
        />


</androidx.drawerlayout.widget.DrawerLayout>

这是包含的应用栏

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        style="@style/Widget.MaterialComponents.AppBarLayout.Primary">

        <androidx.appcompat.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="?actionBarSize"
            android:id="@+id/toolbar"
            app:contentInsetStartWithNavigation="0dp" />
    </com.google.android.material.appbar.AppBarLayout>

</LinearLayout>

最佳答案

我创建了一个名为 LoginActivity 的 Activity ,在其中放置了一个按钮,并创建了一个名为 MainActivity 的 Activity ,在其中放置了抽屉。通过单击按钮,我启动 MainActivity

事实上,我并没有重复你上面所说的问题。

但我建议您可以尝试通过文件模板而不是手动创建带有抽屉的 Activity ,以避免出现一些我们尚未发现的错误。

步骤是:右键包名->新建-> Activity ->抽屉导航 Activity 。

关于java - Android中的 "Top-level destination"是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61024973/

相关文章:

java - 在 Java 中打印 JavaPairRDD<Double, Double> 的值

android - 返回重复假期 Activity 的日历

android - 当没有足够的项目来填充屏幕高度时,如何强制 RecyclerView 滚动

java - 在 for 循环中创建 JfreeCharts

java套接字服务器客户端->服务器->客户端

android - 无法从 Android Studio 的项目结构中删除模块

android - 自 Compose BOM 2023.08.00 以来,仪器测试失败,因为惰性列表更改似乎在层次结构中留下了旧节点

java - 实现搜索栏并在空对象引用错误上获取 'java.lang.Object[] java.util.Collection.toArray()'

java - 来自 java 命令行的 Maven 依赖插件的类路径文件

android - 查看在其他布局后面的动画