Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 正在尝试将导航抽屉按钮添加到应用程序栏_Java_Android_Xml_Android Studio 3.0 - Fatal编程技术网

Java 正在尝试将导航抽屉按钮添加到应用程序栏

Java 正在尝试将导航抽屉按钮添加到应用程序栏,java,android,xml,android-studio-3.0,Java,Android,Xml,Android Studio 3.0,我在跟踪 我在尝试将按钮添加到应用程序栏时被卡住了 当我向右滑动时,导航抽屉就会出现,这样就可以工作了。当我将v7.widget.Toolbar添加到FrameLayout下的XML中时,它会破坏布局,这只是我遇到问题的工具栏中的按钮 最初在我的XML中,我只是有一个约束布局,子视图是Scrollview,内部是LinearView(垂直) 然而,我无法理解为什么这不起作用: <?xml version="1.0" encoding="utf-8"?> <!-- Use Dra

我在跟踪

我在尝试将按钮添加到应用程序栏时被卡住了

当我向右滑动时,导航抽屉就会出现,这样就可以工作了。当我将
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
位于其顶部。我哪里出错了?

NavigationView
放在
FrameLayout
下面

NavigationView
放在
FrameLayout
下面

在MikeM的上述评论之后,他说:

FrameLayout将与其子视图重叠;i、 例如,它将在z轴上一个叠在另一个上。将FrameLayout更改为垂直线性布局,这将沿边对边进行布局。此外,您的NavigationView需要在抽屉布局中最后列出

所以基本上我把我的框架布局改成了线性布局,这样就行了。Android文档就是这样,这有点令人失望,但我所做的就是这样


谢谢你,米肯

在MikeM的上述评论之后,他说:

FrameLayout将与其子视图重叠;i、 例如,它将在z轴上一个叠在另一个上。将FrameLayout更改为垂直线性布局,这将沿边对边进行布局。此外,您的NavigationView需要在抽屉布局中最后列出

所以基本上我把我的框架布局改成了线性布局,这样就行了。Android文档就是这样,这有点令人失望,但我所做的就是这样


谢谢你,米肯

FrameLayout
将重叠其子视图
s;i、 例如,它将在z轴上一个叠在另一个上。将
FrameLayout
更改为垂直
LinearLayout
,这样将沿边对边进行布局。此外,您的
导航视图
需要在
抽屉布局
@MikeM中最后列出。我不明白为什么他们会在教程中指定使用框架布局?这也行!“但我的工具栏颜色不见了,我猜是因为我现在用的是我自己的工具栏。”@MikeM。如果你把它作为一个答案,我会把它标记为正确的。是的,他们把这个例子搞砸了。可悲的是,这并不奇怪。不管怎样,我很好。:-)这是一个常见的问题,如果我有时间找到一个,我可能会把它作为一个副本关闭。如果你愿意的话,可以在你自己的答案中随意发布调整后的布局。不过谢谢你。谢谢你的提议。顺便说一句,是的,你需要自己在
工具栏上设置背景;e、 例如,
android:background=“?attr/colorPrimary”
。干杯<代码>框架布局
将与其子视图
重叠;i、 例如,它将在z轴上一个叠在另一个上。将
FrameLayout
更改为垂直
LinearLayout
,这样将沿边对边进行布局。此外,您的
导航视图
需要在
抽屉布局
@MikeM中最后列出。我不明白为什么他们会在教程中指定使用框架布局?这也行!“但我的工具栏颜色不见了,我猜是因为我现在用的是我自己的工具栏。”@MikeM。如果你把它作为一个答案,我会把它标记为正确的。是的,他们把这个例子搞砸了。可悲的是,这并不奇怪。不管怎样,我很好。:-)这是一个常见的问题,如果我有时间找到一个,我可能会把它作为一个副本关闭。如果你愿意的话,可以在你自己的答案中随意发布调整后的布局。不过谢谢你。谢谢你的提议。顺便说一句,是的,你需要自己在
工具栏上设置背景;e、 例如,
android:background=“?attr/colorPrimary”
。干杯谢谢,但这并没有解决问题。