只提一个有趣的观察。
如果您使用布局结构来获得像这样的左侧和右侧菜单:
<android.support.v4.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"
android:fitsSystemWindows="true">
<!-- MAIN CONTAINER -->
<include layout="@layout/content_home"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/toolbar"/>
<!-- LEFT SIDE MENU -->
<RelativeLayout
android:id="@+id/left_side_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:visibility="visible"
android:fitsSystemWindows="false"
android:background="@color/green">
<!-- put some menu items in here -->
</RelativeLayout>
<!-- RIGHT SIDE MENU -->
<RelativeLayout
android:id="@+id/right_side_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:visibility="visible"
android:fitsSystemWindows="false"
android:background="@color/gray">
<!-- put some items in here -->
</RelativeLayout>
您将很难尝试仅使用以下语句禁用其中一个侧边菜单:
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, findViewById(R.id.right_drawer))
这将锁定整个 DrawerLayout,您将无法滑动任何侧边菜单。
因此,@Alberto Maluje 在上述答案之一下提出的方法将为您提供更大的灵活性。
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, GravityCompat.END);