NavigationDrawer over Toolbar with App.Compat theme

NavigationDrawer over Toolbar with App.Compat theme

我现在混音真的很糟糕。只是对所有选项感到困惑。我有一个抽屉和一个工具栏。抽屉在工具栏下打开。我想打开工具栏上的抽屉以获得更多 space。现在是意大利面,我看不懂

这是我使用的主题:

进口:

import android.support.v4.app.ActivityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;

在class中:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mActionBar = getSupportActionBar();

mActionBar.setDisplayHomeAsUpEnabled(true);
mActionBar.setDisplayShowHomeEnabled(true);
mActionBar.setHomeButtonEnabled(true);


 mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) {
    @Override
    public void onDrawerOpened(View drawerView) {
        super.onDrawerOpened(drawerView);
        invalidateOptionsMenu();
    }

    @Override
    public void onDrawerClosed(View drawerView) {
        super.onDrawerClosed(drawerView);
        invalidateOptionsMenu();
    }
    };


        if (mDrawerToggle != null && mDrawerLayout != null) {
            mDrawerLayout.setDrawerListener(mDrawerToggle);
        }

布局中:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" >

        <Spinner
            android:id="@+id/spinner_menu"
            style="@style/spinner_style"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:prompt="@string/search" />
    </include>

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

        <!-- Framelayout to display Fragments -->

        <FrameLayout
            android:id="@+id/frame_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <!-- Listview to display slider menu -->

        <LinearLayout
            android:id="@+id/left_drawer_layout"
            android:layout_width="@dimen/navigation_drawer_max_width"
            android:layout_height="wrap_content"
            android:layout_gravity="start"
            android:orientation="vertical" >

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="48dp" >

                <EditText
                    android:id="@+id/searchMenuTxt"
                    style="@style/Base.AlertDialog.AppCompat"
                    android:layout_width="match_parent"
                    android:layout_height="48dp"
                    android:background="@color/list_background"
                    android:gravity="center|left"
                    android:hint="@string/search"
                    android:paddingLeft="8dp"
                    android:paddingRight="8dp"
                    android:focusable="false" 
                     android:focusableInTouchMode="true"
                    android:textColor="@android:color/white"
                    android:textColorHint="@android:color/darker_gray" >
                </EditText>

                <ListView
                android:id="@+id/activeChatsList"
                android:layout_width="@dimen/navigation_drawer_max_width"
                android:layout_height="wrap_content"
                android:layout_gravity="start"
                android:background="@drawable/list_selector"
                android:choiceMode="singleChoice"
                android:divider="@android:color/transparent"
                android:dividerHeight="1dp"
                android:listSelector="@drawable/list_selector"
                android:minHeight="50dp" />

                <Button
                    android:id="@+id/clearBtn"
                    android:layout_width="24dp"
                    android:layout_height="24dp"
                    android:paddingRight="8dp"
                    android:layout_gravity="right|center"
                    android:background="@drawable/clear" />
            </FrameLayout>

            <ListView
                android:id="@+id/list_slidermenu"
                android:layout_width="@dimen/navigation_drawer_max_width"
                android:layout_height="wrap_content"
                android:layout_gravity="start"
                android:background="@drawable/list_selector"
                android:choiceMode="singleChoice"
                android:divider="@android:color/transparent"
                android:dividerHeight="1dp"
                android:listSelector="@drawable/list_selector"
                android:minHeight="250dp" />
        </LinearLayout>
    </android.support.v4.widget.DrawerLayout>

</LinearLayout>

我为 activity 使用的主题是:

<style name="MyTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="windowActionModeOverlay">true</item>
        <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
        <item name="colorPrimary">@color/blue</item>
        <item name="android:textColor">@android:color/white</item>
        <item name="colorPrimaryDark">@color/blue</item>
        <!-- <item name="android:editTextStyle">@style/my_custom_edit_text_style</item> -->
        <item name="android:dialogTheme">@style/MyDialogTheme</item>
        <item name="android:alertDialogTheme">@style/MyDialogTheme</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
    </style>

我不知道如何取消混合。我想这样做应该不难吧?我需要一个额外的眼睛...谢谢。

您只需要稍微修改一下您的 layout.xml 文件:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        android:orientation="vertical">

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar">

            <Spinner
                android:id="@+id/spinner_menu"
                style="@style/spinner_style"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:prompt="@string/search" />
        </include>

        <!-- Framelayout to display Fragments -->

        <FrameLayout
            android:id="@+id/frame_container"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

    </LinearLayout>

    <!-- Listview to display slider menu -->

    <LinearLayout
        android:id="@+id/left_drawer_layout"
        android:layout_width="@dimen/navigation_drawer_max_width"
        android:layout_height="wrap_content"
        android:layout_gravity="start"
        android:orientation="vertical">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="48dp">

            <EditText
                android:id="@+id/searchMenuTxt"
                style="@style/Base.AlertDialog.AppCompat"
                android:layout_width="match_parent"
                android:layout_height="48dp"
                android:background="@color/list_background"
                android:focusable="false"
                android:focusableInTouchMode="true"
                android:gravity="center|left"
                android:hint="@string/search"
                android:paddingLeft="8dp"
                android:paddingRight="8dp"
                android:textColor="@android:color/white"
                android:textColorHint="@android:color/darker_gray"></EditText>

            <ListView
                android:id="@+id/activeChatsList"
                android:layout_width="@dimen/navigation_drawer_max_width"
                android:layout_height="wrap_content"
                android:layout_gravity="start"
                android:background="@drawable/list_selector"
                android:choiceMode="singleChoice"
                android:divider="@android:color/transparent"
                android:dividerHeight="1dp"
                android:listSelector="@drawable/list_selector"
                android:minHeight="50dp" />

            <Button
                android:id="@+id/clearBtn"
                android:layout_width="24dp"
                android:layout_height="24dp"
                android:layout_gravity="right|center"
                android:background="@drawable/clear"
                android:paddingRight="8dp" />
        </FrameLayout>

        <ListView
            android:id="@+id/list_slidermenu"
            android:layout_width="@dimen/navigation_drawer_max_width"
            android:layout_height="wrap_content"
            android:layout_gravity="start"
            android:background="@drawable/list_selector"
            android:choiceMode="singleChoice"
            android:divider="@android:color/transparent"
            android:dividerHeight="1dp"
            android:listSelector="@drawable/list_selector"
            android:minHeight="250dp" />
    </LinearLayout>
</android.support.v4.widget.DrawerLayout>