Issue
My problem is as follows: I lock the navigation drawer menu setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN)
in the landscape mode of the tablet, but I need the fragment from the right to be active, so I can click it with navigation always opened. But I dont know how to do it. Please help.
Solution
There are a few things you need to do:
Disable the layout fading by setting a transparent color:
drawer.setScrimColor(Color.TRANSPARENT);
Lock the drawer
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN);
Create a custom drawer class which allows clicking through when in locked mode:
public class CustomDrawer extends DrawerLayout { public CustomDrawer(Context context) { super(context); } public CustomDrawer(Context context, AttributeSet attrs) { super(context, attrs); } public CustomDrawer(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { View drawer = getChildAt(1); if (getDrawerLockMode(drawer) == LOCK_MODE_LOCKED_OPEN && ev.getRawX() > drawer.getWidth()) { return false; } else { return super.onInterceptTouchEvent(ev); } } }
Use this class in xml:
<com.example.myapplication.CustomDrawer xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"> <!-- The main content view --> </FrameLayout> <ListView android:layout_width="100dp" android:layout_height="match_parent" android:layout_gravity="start" android:background="#111"/> </com.example.myapplication.CustomDrawer>
Answered By - Simas
Answer Checked By - Candace Johnson (JavaFixing Volunteer)