答案 0 :(得分:0)
查看您的MainActivity XML,您将找到以下结构:
<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=".MainActivity">
<FrameLayout android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- you can custom your layout here in LinearLayout-->
<LinearLayout android:id="@+id/navigation_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
tools:layout="@layout/fragment_navigation_drawer" >
<!-- you can add a button here-->
<Button
android:id="@+id/Button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="mButton"/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
您可以在片段中自定义视图,或者使用此处的Linearlayout并在布局中填充按钮。
mLinearLayout = (LinearLayout) findViewById(R.id.navigation_drawer);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mButton = (DrawerLayout) findViewById(R.id.Button1);
mButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//close DrawerLayout here
mDrawerLayout.closeDrawer(mLinearLayout);
}
});
您可以使用片段替换FrameLayout:
FragmentTransaction fragmentTransaction1 = fragmentManager
.beginTransaction();
fragmentTransaction1.replace(R.id.content_frame,
overviewFragment);
fragmentTransaction1.commit();