public void setDrawerLeftEdgeSize(DrawerLayout drawerLayout, float displayWidthPercentage) { if (drawerLayout == null) return; try { // find ViewDragHelper and set it accessible Field leftDraggerField = drawerLayout.getClass().getDeclaredField("mLeftDragger"); leftDraggerField.setAccessible(true); ViewDragHelper leftDragger = (ViewDragHelper) leftDraggerField.get(drawerLayout); // find edgesize and set is accessible Field edgeSizeField = leftDragger.getClass().getDeclaredField("mEdgeSize"); edgeSizeField.setAccessible(true); int edgeSize = edgeSizeField.getInt(leftDragger); // set new edgesize // Point displaySize = new Point(); DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); edgeSizeField.setInt(leftDragger, Math.max(edgeSize, (int) (dm.widthPixels * displayWidthPercentage))); } catch (Exception e) { // ignore } }
时间: 2024-10-10 18:44:47