我有这个MainActivity.xml,我希望当我的ListView(抽屉导航)在ToolBar上打开时。
我的XML更改足以获得结果吗? 如果可以使用ToolBar和样式。
<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"
tools:context=".MainActivity"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/primary"
app:theme="@style/ToolbarTheme"
app:popupTheme="@style/Theme.AppCompat"/>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ListView
android:id="@+id/left_drawer"
android:background="@android:color/white"
android:layout_width="305dp"
android:layout_height="match_parent"
android:layout_gravity="start"/>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
&#13;
styles.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.AppCompat.Light.NoActionBar" parent="@style/Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primaryDark</item>
</style>
<style name="AppTheme" parent="AppTheme.Base">
</style>
<style name="ToolbarTheme" parent="Theme.AppCompat">
<item name="android:textColorPrimary">@color/abc_primary_text_material_dark</item>
<item name="actionMenuTextColor">@color/abc_primary_text_material_dark</item>
<item name="android:textColorSecondary">@color/abc_secondary_text_material_dark</item>
</style>
</resources>
&#13;
答案 0 :(得分:0)
删除根LinearLayouta移动drawerlayout内的工具栏
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity"
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:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/primary"
app:theme="@style/ToolbarTheme"
app:popupTheme="@style/Theme.AppCompat"/>
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<ListView
android:id="@+id/left_drawer"
android:background="@android:color/white"
android:layout_width="305dp"
android:layout_height="match_parent"
android:layout_gravity="start"/>
</android.support.v4.widget.DrawerLayout>