ActionBar(V7)的添加非常简单,只需要在AndroidManifest.xml中指定Application或Activity的theme是Theme.Holo或其子类就可以了,在Android 3.0及更高的版本中,Activity中都默认包含有ActionBar组件。
drawerLayout(V4)是Support Library包中实现了侧滑菜单效果的控件,可以说drawerLayout是因为第三方控件如MenuDrawer等的出现之后,google借鉴而出现的产物。drawerLayout分为侧边菜单和主内容区两部分,侧边菜单可以根据手势展开与隐藏(drawerLayout自身特性),主内容区的内容可以随着菜单的点击而变化(这需要使用者自己实现)。
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent"> <com.heima.googleplay.widget.PagerTab android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="42dip" android:background="@drawable/bg_tab"/> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/tabs" tools:context=".MainActivity"/> </RelativeLayout> <FrameLayout android:id="@+id/start_drawer" android:layout_width="250dp" android:layout_height="match_parent" android:layout_gravity="start" android:background="@drawable/bg_tab"></FrameLayout> </android.support.v4.widget.DrawerLayout>