导航抽屉没有折叠,没有汉堡包按钮

我的抽屉布局显示为正常活动,工具栏中没有任何按钮,也没有以任何方式折叠..我希望它来自右侧。


这是我的抽屉活动布局..


    <?xml version="1.0" encoding="utf-8"?>

<android.support.v4.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:layout_height="match_parent"

    tools:context=".myDrawer"

    tools:openDrawer="start">


    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:orientation="vertical">


        <android.support.v7.widget.Toolbar

            android:layout_width="match_parent"

            android:layout_height="?attr/actionBarSize"

            android:background="#000"

            android:id="@+id/drawer_toolbar"

            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">


        </android.support.v7.widget.Toolbar>


        <FrameLayout

            android:id="@+id/fragment_container"

            android:layout_width="match_parent"

            android:layout_height="match_parent">


        </FrameLayout>


    </LinearLayout>


<android.support.design.widget.NavigationView

    android:background="@color/colorPrimaryDark"

    android:layout_width="100dp"

    android:layout_height="match_parent"

    android:foregroundGravity="left"

    app:menu="@menu/drawer_menu"

    app:headerLayout="@layout/nav_header">


</android.support.design.widget.NavigationView>


</android.support.v4.widget.DrawerLayout>

这是我的 nav_header.xml 布局。


    <?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:orientation="vertical" android:layout_width="wrap_content"

    android:layout_height="300dp"

    android:padding="15dp"

    android:theme="@style/ThemeOverlay.AppCompat.Dark">

<ImageView

    android:layout_width="100dp"

    android:layout_height="200dp"

    android:src="@drawable/hhh"

    />



收到一只叮咚
浏览 94回答 1
1回答

智慧大石

用下面替换您的导航视图<android.support.design.widget.NavigationView&nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_gravity="start"&nbsp; &nbsp; &nbsp; &nbsp; android:fitsSystemWindows="true"&nbsp; &nbsp; &nbsp; &nbsp; app:headerLayout="@layout/nav_header"&nbsp; &nbsp; &nbsp; &nbsp; app:menu="@menu/my_menu">&nbsp; &nbsp; </android.support.design.widget.NavigationView>添加以下方法以显示切换public void addToggel() {&nbsp; &nbsp; &nbsp; &nbsp; DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);&nbsp; &nbsp; &nbsp; &nbsp; ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);&nbsp; &nbsp; &nbsp; &nbsp; //drawer.setDrawerListener(toggle);&nbsp; &nbsp; &nbsp; &nbsp; drawer.addDrawerListener(toggle);&nbsp; &nbsp; &nbsp; &nbsp; toggle.syncState();&nbsp; &nbsp; &nbsp; &nbsp; NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);&nbsp; &nbsp; }在 string.xml 中添加以下字符串<string name="navigation_drawer_open">open</string>&nbsp; &nbsp; <string name="navigation_drawer_close">close</string>根据您的代码更新抽屉布局 ID 和导航视图 ID让我知道更多帮助
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java