DrawerLayout xml文件
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="net.oschina.gitapp.ui.MainActivity" >
<!-- 界面内容 -->
<FrameLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- 菜单 -->
<FrameLayout
android:id="@+id/main_slidingmenu_frame"
android:layout_width="260dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:name="net.oschina.gitapp.ui.DrawerNavigationMenu"
tools:layout="@layout/activity_main_drawer_menu"
android:background="#343636"
android:orientation="vertical" />
</android.support.v4.widget.DrawerLayout>
//声明
//初始化
//使用
private DrawerLayout mDrawerLayout;
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLayout.setDrawerListener(new DrawerMenuListener());
// 设置滑出菜单的阴影效果
//mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,GravityCompat.START);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
null, 0, 0);
main_content元素和main_slidingmenu_frame元素被替换
//
private FragmentManager mFragmentManager;
//
mFragmentManager = getSupportFragmentManager();
//使用其他Fragment元素动态替换
FragmentTransaction ft = mFragmentManager.beginTransaction();
ft.replace(R.id.main_slidingmenu_frame,
mMenu, DRAWER_MENU_TAG)
.replace(R.id.main_content,
ExploreViewPagerFragment.newInstance(),
DRAWER_CONTENT_TAG).commit();
将mDrawerLayout作为参数构建mDrawerToggle
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLayout.setDrawerListener(new DrawerMenuListener());
// 设置滑出菜单的阴影效果
//mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,GravityCompat.START);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
null, 0, 0);