android学习之侧边菜单滑动,toolbar+DrawerLayout
toolbar上篇有写,首先在xml文件中加入DrawerLayout,记住加上id
<android.support.v4.widget.DrawerLayout>
android:id="@+id/drawer_layout"
......
</android.support.v4.widget.DrawerLayout>
DrawerLayout里面的内容需要写主内容区布局和侧边布局(或者选其一)(类似主内容写在了DrawerLayout布局中),内容区布局写在侧边布局前面;
另外控制侧边菜单从哪边滑出的:
android:layout_gravity="start"
实现DrawerLayout布局不覆盖住toolbar,需要toolbar写在DrawerLayout前,整个xml代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!--toolbar-->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.7"
android:background="@color/colorAccent"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme">
<TextView
android:layout_width=