I am using the new Navigation Drawer in my app. It is great except I have not found an easy way to set how the drawer is open. The default behavior is drag from the left edge of the screen to open. This is fine, unless the phone/table has a case on and the edge of phone can not be touched. I would like to allow the user to touch and drag from a margin of the screen to the left. This is easy to set with other nav drawer libs(Sliding lib). I have not seen anything with Google's lib unfortunately.
There is an onTouchEvent() method for the NavigationLayout that could may be used. Of course you could listen to all touch events and trigger an openDrawer, but was hoping for an easy way with less code. Any ideas?
Android App Development for BeginnersStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. Step 3 − Add the following code to res/layout/nav_header_main.
DrawerLayout acts as a top-level container for window content that allows for interactive "drawer" views to be pulled out from one or both vertical edges of the window.
Here I've found a solution via reflections
DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); Field mDragger = mDrawerLayout.getClass().getDeclaredField( "mLeftDragger");//mRightDragger for right obviously mDragger.setAccessible(true); ViewDragHelper draggerObj = (ViewDragHelper) mDragger .get(mDrawerLayout); Field mEdgeSize = draggerObj.getClass().getDeclaredField( "mEdgeSize"); mEdgeSize.setAccessible(true); int edge = mEdgeSize.getInt(draggerObj); mEdgeSize.setInt(draggerObj, edge * 5); //optimal value as for me, you may set any constant in dp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With