Full width Navigation Drawer

后端 未结 14 771
名媛妹妹
名媛妹妹 2020-12-08 03:57

I\'d like to create a full width navigation drawer. Setting layout_width to match_parent on @+id/left_drawer yields in width of about

14条回答
  •  一向
    一向 (楼主)
    2020-12-08 04:37

    Another possible way to solve the issue without overriding too much:

    public class FullScreenDrawerLayout extends DrawerLayout {
    
    ... //List of constructors calling
    ... //super(...);
    ... //init();
    
    /** Make DrawerLayout to take the whole screen. */
    protected void init() {
        try {
    
            Field field = getClass().getSuperclass().getDeclaredField("mMinDrawerMargin");
            field.setAccessible(true);
            field.set(this, Integer.valueOf(0));
    
        } catch (Exception e) {
            throw new IllegalStateException("android.support.v4.widget.DrawerLayout has changed and you have to fix this class.", e);
        }
    }
    

    }

    If, at some point, support library is updated and mMinDrawerMargin is not there anymore you will get exception and fix problem before you publish your next update.

    I didn't make measurements, but suppose there is not so many reflection to affect performance. Furthermore, it executes only per view creation.

    PS it's strange why DrawerLayout is made so inflexible (I'm about private min margin) at this point...

提交回复
热议问题