[android studio中的导航视图问题

问题描述 投票:0回答:1

我尝试使用导航视图,但是没有用。我还清理了该项目,然后再次构建它,然后使该项目无效,但没有用。

enter image description here

navigation-drawer android-drawable navigationbar navigationview android-navigationview
1个回答
0
投票

也许是它的错误,您可以尝试在主视图中添加tools:openDrawer =“ start”

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawerLayout"
    android:fitsSystemWindows="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:openDrawer="start">

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <include layout="@layout/app_bar_default"/>
        <fragment
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:id="@+id/nav_host_fragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:name="androidx.navigation.fragment.NavHostFragment"
            app:defaultNavHost="true"
            app:navGraph="@navigation/nav_graph"
            />
    </androidx.coordinatorlayout.widget.CoordinatorLayout>

        <com.google.android.material.navigation.NavigationView
            android:id="@+id/navigationView"
            android:layout_gravity="start"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:headerLayout="@layout/navigation_header_main"
            app:menu="@menu/drawer_menu"
            />

</androidx.drawerlayout.widget.DrawerLayout>
© www.soinside.com 2019 - 2024. All rights reserved.