我正在使用 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/