Question

Like i ask in the title, i will like to know if there is any way to interact with my content fragment whyle i have the drawer open and locked (in top of it also disable the app button click when the drawer is locked).

I know there is others solutions (like define a new layout with a simple listView instead of a drawer) but i will like to keep the drawer to save time and code.

Thanks in advance to everyone.

Was it helpful?

Solution

I had a similar problem. I created a custom DrawerLayout class that passes touch events to the main content view after processing them. Your mileage may vary, but it seems to be working for me:

import android.content.Context;
import android.support.v4.widget.DrawerLayout;
import android.util.AttributeSet;
import android.view.MotionEvent;

public class TouchForwardingDrawerLayout extends DrawerLayout {

   public TouchForwardingDrawerLayout( Context context, AttributeSet attrs ) {
      super( context, attrs );
   }

   @Override
   public boolean onTouchEvent( MotionEvent event ) {
      boolean r = super.onTouchEvent( event );
      getChildAt( 0 ).dispatchTouchEvent( event );
      return r;
   }
}

OTHER TIPS

I've also noticed similar behavior when locking drawer pane. To resolve this in a convenient way, simply bring your fragment content view outside the DrawerLayout in layout-XML. For example:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v4.widget.DrawerLayout
        android:id="@id/layoutDrawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:saveEnabled="false">

        <!-- content is outside this drawer layout
        because locking the drawer also disables
        touchevents propagation to layoutContentFrame -->

        <!-- navigation drawer -->
        <LinearLayout
            android:layout_height="match_parent"
            android:layout_width="@dimen/width_drawer_left"
            android:orientation="vertical"
            android:layout_gravity="left|start"
            android:padding="10dp"
            android:background="@color/drawer_left_background">

            <ListView
                android:id="@id/drawerLeft"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:choiceMode="singleChoice" />
        </LinearLayout>

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


    <!-- content view -->
    <FrameLayout
        android:id="@id/layoutContentFrame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="@dimen/width_drawer_left">

        <!-- content will be added as fragments here -->
    </FrameLayout>

</RelativeLayout>

At least it resolved my issue without any hack in code :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top