0

我正在使用 Java 在 Android Studio 中工作。我想实现一个导航抽屉(那些从左到右滑动的),汉堡图标总是在顶部。但是有一些“顶级目的地”的问题,没有这个汉堡图标就不会出现。我找到的解决方案之一是将该活动作为我的 Launcher 活动,但我不希望这样。

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

这是我的导航布局

<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>
4

1 回答 1

0

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

其实你上面说的问题我并没有重复。

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

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

于 2020-04-04T09:21:12.940 回答