Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.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
Android工具栏占据全屏_Android - Fatal编程技术网

Android工具栏占据全屏

Android工具栏占据全屏,android,Android,以下是我所有的相关代码: Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle("sometitle"); toolbar.inflateMenu(R.menu.menu_main); setSupportActionBar(toolbar); 风格: <resources> <!-- Base application theme. --> &l

以下是我所有的相关代码:

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("sometitle");
    toolbar.inflateMenu(R.menu.menu_main);
    setSupportActionBar(toolbar);
风格:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/sunshine_blue</item>
    <item name="colorPrimaryDark">@color/sunshine_dark_blue</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    <item name="windowActionBar">false</item> <!-- Remove the default action bar -->
    <item name="windowNoTitle">true</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
    <item name="spinBars">true</item>
    <item name="color">@android:color/white</item>
</style>

@颜色/阳光蓝
@颜色/阳光\深\蓝色
@样式/抽屉箭头样式
错误的
符合事实的
符合事实的
@android:彩色/白色

XML:



结果如下:

可能的解决方案是将工具栏移到抽屉布局外,并将这两个工具栏放在框架布局内

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:paddingTop="?attr/actionBarSize"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!-- The main content view -->
        <fragment
            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:id="@+id/fragment"
            android:name="com.***.***.***.MainActivityFragment"
            tools:layout="@layout/fragment_main" android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <!-- The navigation drawer -->
        <ListView
            android:id="@+id/left_drawer"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp"
            android:background="#111"/>

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

    <!-- Replace the default action bar -->
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_height="?attr/actionBarSize"
        android:layout_width="match_parent"
        android:elevation="5dp"
        android:background="?attr/colorPrimary" />

</FrameLayout>

可能的解决方案是将工具栏移到抽屉布局外,并将这两个工具栏放在框架布局内

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:paddingTop="?attr/actionBarSize"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!-- The main content view -->
        <fragment
            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:id="@+id/fragment"
            android:name="com.***.***.***.MainActivityFragment"
            tools:layout="@layout/fragment_main" android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <!-- The navigation drawer -->
        <ListView
            android:id="@+id/left_drawer"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp"
            android:background="#111"/>

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

    <!-- Replace the default action bar -->
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_height="?attr/actionBarSize"
        android:layout_width="match_parent"
        android:elevation="5dp"
        android:background="?attr/colorPrimary" />

</FrameLayout>

抽屉布局只允许两个孩子使用。从:

  • 主内容视图(上面的框架布局)必须是 抽屉布局中的第一个子项,因为XML顺序暗示 z-排序和抽屉必须位于内容的顶部
  • 主要 内容视图设置为匹配父视图的宽度和高度, 因为当导航抽屉打开时,它代表整个UI 隐藏的

尝试将
工具栏
片段
包装在
框架布局
抽屉布局
只允许两个子项。从:

  • 主内容视图(上面的框架布局)必须是 抽屉布局中的第一个子项,因为XML顺序暗示 z-排序和抽屉必须位于内容的顶部
  • 主要 内容视图设置为匹配父视图的宽度和高度, 因为当导航抽屉打开时,它代表整个UI 隐藏的


尝试在
框架布局中包装
工具栏
片段

可能需要指定固定高度,而不是使用
包装内容
?如果删除minheight和maxHeight并使用特定大小而不是包装内容会怎么样?但硬编码大小是一种糟糕的做法,对吗?这是您需要的唯一XML代码吗有你不是在另一个视图中包装代码,比如框架布局或相对布局吗?不,我是@rogerthatcode。。顺便说一句,为了方便起见,我尝试了硬编码的大小,但在神话中它不起作用。可能需要指定一个固定的高度,而不是使用
wrap\u content
?如果删除minheight和maxHeight,并使用特定的大小而不是wrap\u content呢?但是硬编码的大小是一种糟糕的做法,对吗?这是您仅有的XML代码吗? 你不是在另一个视图中包装代码,比如框架布局或相对布局吗?不,我是@rogerthatcode。。顺便说一句,为了它,我尝试了一下硬编码的尺寸,但它在神话中不起作用。谢谢。。不过我已经得到了答案+1(我知道我们不应该发表这样的评论,但我认为这条规则没有意义,我们应该如何理解)这解释了问题的根本原因,而不仅仅是一个解决方案,谢谢!谢谢不过我已经得到了答案+1(我知道我们不应该发表这样的评论,但我认为这条规则没有意义,我们应该如何理解)这解释了问题的根本原因,而不仅仅是一个解决方案,谢谢!最后一件事(很抱歉)我的汉堡包没有旋转和动画到后退按钮,尽管我已经在样式中设置了
true
。请勾选这篇文章,它实际上就是我所关注的。。我编辑了原始问题中的样式,以便您可以看到全局。如果是这样,
工具栏将覆盖
抽屉布局的一部分
@chinanichen属性
android:paddingTop=“?attr/actionBarSize”
DrawerLayout
上的
将确保内部碎片不会被
工具栏
覆盖,因为它将填充设置为等于
工具栏的高度
最后一件事(很抱歉)虽然我在样式中设置了
true
,但我的汉堡包并没有旋转,也没有设置后退按钮的动画。请勾选我所关注的这篇文章。。我编辑了原始问题中的样式,以便您可以看到全局。如果是这样,
工具栏将覆盖
抽屉布局的一部分
@chinanichen属性
android:paddingTop=“?attr/actionBarSize”
抽屉布局
上的
将确保内部碎片不会被
工具栏
覆盖,因为它将填充设置为等于
工具栏高度