Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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_Xml_Android Actionbar_Navigation Drawer - Fatal编程技术网

Android 自动添加工具栏

Android 自动添加工具栏,android,xml,android-actionbar,navigation-drawer,Android,Xml,Android Actionbar,Navigation Drawer,我试图在下面的代码中将导航抽屉放在操作栏/工具栏的顶部。问题是,我没有在xml文件中添加工具栏,并且在style.xml文件中actionbar设置被设置为false。不过,仍然会在窗口中自动添加一个actionbar内容。我不知道是什么原因导致添加此操作栏/工具栏 代码如下: NavigationDrawer\u Activity.xml <?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.Dr

我试图在下面的代码中将导航抽屉放在操作栏/工具栏的顶部。问题是,我没有在xml文件中添加工具栏,并且在style.xml文件中actionbar设置被设置为false。不过,仍然会在窗口中自动添加一个actionbar内容。我不知道是什么原因导致添加此操作栏/工具栏

代码如下:

NavigationDrawer\u Activity.xml

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    >

  **<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay"
    >
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />
    </android.support.design.widget.AppBarLayout>**    
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Layout Here"
        android:gravity="center"/>

    <android.support.design.widget.NavigationView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:layout_gravity="start"
        app:headerLayout="@layout/navigation_view_header_layout"
        app:menu="@menu/navigation_view_list_items"/>

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

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

**
**    
styles.xml

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    >

  **<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay"
    >
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />
    </android.support.design.widget.AppBarLayout>**    
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Layout Here"
        android:gravity="center"/>

    <android.support.design.widget.NavigationView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:layout_gravity="start"
        app:headerLayout="@layout/navigation_view_header_layout"
        app:menu="@menu/navigation_view_list_items"/>

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

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>
    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

@颜色/原色
@颜色/原色暗
@颜色/颜色重音
错误的
符合事实的
问题:

  • 如果我没有添加此工具栏,是什么导致它出现的
  • 如何将NavigationDrawer置于自动添加的工具栏之上

最好删除windowActionBar属性并将父样式更改为:

 <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

您正在此处添加工具栏:

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:popupTheme="@style/AppTheme.PopupOverlay" />

删除此选项以避免在清单中显示工具栏?

改变

android:theme="@style/AppTheme" 


我完全错过了。问题仍然存在。工具栏现在覆盖整个屏幕。并单击导航抽屉列表项不起作用。请查看已编辑的NavigationDrawer_Activity.xml如果我误解了您的问题,请原谅,我已编辑了我的答案。似乎你正在添加工具栏,当你不想要的时候,就把它删除?不,我想删除一个由主题自动添加的工具栏。我的要求是将幻灯片导航抽屉放在手动添加的工具栏顶部。但是现在,当我在xml文件中添加工具栏时,它填充了整个显示,导航视图中的项目变得不可读。您需要AppBarLayout吗?我认为AppTheme.PopupOverlay可能是您的罪魁祸首尝试删除它。