Set drag margin for Android Navigation Drawer

后端 未结 1 526
余生分开走
余生分开走 2020-12-01 00:21

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 e

相关标签:
1条回答
  • 2020-12-01 00:48

    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
    
    0 讨论(0)
提交回复
热议问题