0

I'll start by being clear - I do not want to close/hide the drawer. That is trivial. I want to remove it entirely.

I have inherited a project in which we use a 'Debug Drawer' - A drawer which shows in debug builds but not in the production application. The layout is as follows. Having the ScrollView as visibility="gone" has no effect.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout android:id="@+id/activity_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <ScrollView android:id="@+id/debug_drawer"
        android:visibility="gone"
        android:layout_width="290dp"
        android:layout_height="match_parent"
        android:layout_gravity="end" />

    <fragment android:id="@+id/navigation_drawer"
        android:name="com.app.NavigationFragment"
        android:layout_width="290dp"
        android:layout_height="match_parent"
        android:layout_gravity="start" />

</android.support.v4.widget.DrawerLayout>

I have tried the following without success

@Override
public void setContentView(int layoutResID) {
    super.setContentView(R.layout.activity_layout);
    if (BuildConfig.DEBUG) {
        final ViewGroup debugDrawerContainer = findById(this, R.id.debug_drawer);
        debugDrawerContainer.setVisibility(View.VISIBLE);
    }
}
Nick Cardoso
  • 20,807
  • 14
  • 73
  • 124
  • I'm surprised it doesn't blow up to be honest. As far as i know, a `DrawerLayout` is meant to contain two children. One for the "main view" and the other as the drawer overlay. Can't you add the debug stuff inside the `navigation_drawer` but hide it if it's not a debug build? Another solution (which is more complex) is to do it via code like described here: http://stackoverflow.com/questions/17861755/drawerlayout-double-drawer-left-and-right-drawers-simultaneously – kha Dec 29 '15 at 11:02
  • Having two drawers has always been supported. The linked answer tells me how to open/close the drawers, that's not what I need to do – Nick Cardoso Dec 29 '15 at 11:04
  • you could provide two gradle/flavours variants. One for debug and one for production – Blackbelt Dec 29 '15 at 11:08
  • You're right. My bad. I'd never seen more than one and the official documentation only had 1 in it last time i read it. – kha Dec 29 '15 at 11:17

1 Answers1

0

I have found a way to do this now, as below.

This is a hack though and a better way to do this if you have the option, is to create another build variant with a flag to disable the drawer (ie. tell android not create the drawer in the first place when not in debug, as suggested by blackbelt)

final ViewGroup debugDrawerContainer = findById(this, R.id.debug_drawer);
if (BuildConfig.DEBUG) {
    ...
} else {
    ((ViewGroup) debugDrawerContainer.getParent()).removeView(debugDrawerContainer);
}
Nick Cardoso
  • 20,807
  • 14
  • 73
  • 124