首页 > 解决方案 > 尝试将导航抽屉按钮添加到应用栏

问题描述

我正在关注本教程

我被困在我试图将按钮添加到应用栏的地方。

当我向右滑动时,会出现导航抽屉,这样就可以了。它只是我遇到问题的栏中的按钮,当我将其添加v7.widget.Toolbar到 FrameLayout 下的 XML 中时,它会破坏布局。

最初在我的 XML 中,我只有一个约束布局,其中一个 Scrollview 作为子项,在其中一个 LinearView(垂直)。

但是我无法理解为什么这不起作用:

<?xml version="1.0" encoding="utf-8"?>
<!-- Use DrawerLayout as root container for activity -->
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">


    <!-- Container for contents of drawer - use NavigationView to make configuration easier -->
    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:menu="@menu/drawer_view"
        app:headerLayout="@layout/nav_header" />

    <!-- Layout to contain contents of main body of screen (drawer will slide over this) -->
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >


        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar" />

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">



            <LinearLayout
                android:id="@+id/seeds_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginBottom="8dp"
                android:layout_marginEnd="8dp"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="8dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="16dp"
                android:background="@drawable/customborder"
                android:orientation="vertical"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"></LinearLayout>
        </ScrollView>

    </FrameLayout>

当我运行它时,顶部栏似乎超过了整个窗口并且颜色消失并且按钮不可点击,因为LinearLayout它在它的顶部。我哪里错了?

标签: javaandroidxmlandroid-studio-3.0

解决方案


放在NavigationView下面FrameLayout


推荐阅读