主页面布局:
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--主体自己单独存在-->
====这里是自己主页面的布局=====
<!--主体自己单独存在-->
<!--这里是侧滑的部分,也可以用其他布局来代替,为了使用design库里面的这里就使用design NavigationView-->
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="@dimen/dp_245"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="@drawable/qiehuan_ertong">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dp_35">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="切换儿童"
android:textColor="@color/white"
android:textSize="@dimen/dp_11" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/dp_35"
android:background="@drawable/border_top_white_5">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_child_switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_15"
android:layout_marginTop="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_15" />
</RelativeLayout>
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
//禁止滑动
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
//将侧边栏顶部延伸至status bar
mDrawerLayout.setFitsSystemWindows(true);
//将主页面顶部延伸至status bar;虽默认为false,但经测试,DrawerLayout需显示设置
mDrawerLayout.setClipToPadding(false);
打开抽屉
mDrawerLayout.openDrawer(GravityCompat.START);