关于DrawerLayout,官方网站给出了相当好的案例
不过对于版本的限定,要求比较高
不过去掉ActionBarDrawerToggle,更换android.app.Fragment
就可以兼容到8了
老规矩,先看效果图,不然浪费大家的时间就是罪过了
看目录结构:
fragment中的内容都一样,如果在实际开发中,下面的实现有损性能,各位可以自己优化下
先看布局文件activity_main.xml:
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/body_background" >
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#293236"
android:gravity="center_vertical" >
<Button
android:id="@+id/left"
style="@style/ButtonHeadStyle"
android:text="Menu" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"