Navigation drawer - disable click on items behind the drawer

Is there a way to make sure the navigation box stays on top of the contents of the fragment?

I created a small test application with dummy data. 10 fragments with the corresponding numbered button and text view. The problem is that the elements of the fragment seem to have a higher priority than the navigation box.

enter image description here

As you can see in the screenshot, as soon as I try to open the "0-fragment", it will instead register a click on the button located behind the navigation box. Clicking on any other content item works fine, but there will be no other interacting items below them for now. What can I do to keep the navigation box correctly on top of the content behind it?

+48
android android-fragments navigation-drawer click-through
Jul 6 '13 at 0:36
source share
5 answers

Set the android:clickable="true" tag to the layout of the sliding panel.

+121
Oct 10 '13 at
source share

The problem is not due to focusing clicks,

Visit https://developer.android.com/training/implementing-navigation/nav-drawer.html#DrawerLayout

The main kind of content (FrameLayout above) should be the first child in DrawerLayout, because the XML order implies a z-order, and the box must be on top of the content.

+4
Sep 23 '15 at 9:32
source share

In my snippet box, I installed TouchListener to return True. It worked for me

  mFragmentContainerView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); 
+3
Nov 06 '15 at 4:31 on
source share

I decided it differently.

Here is my code for setting up the box:

 /** * Setup Navigation Drawer */ private void setDrawer() { NavigationDrawerFragment mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.fragment_drawer); mNavigationDrawerFragment.setup(R.id.fragment_drawer, (DrawerLayout) findViewById(R.id.drawer), mToolbar); } 

The setup method is inside my NavigationDrawerFragment , here is my code for it:

 /** * Users of this fragment must call this method to set up the navigation drawer interactions. * * @param fragmentId The android:id of this fragment in its activity layout. * @param drawerLayout The DrawerLayout containing this fragment UI. * @param toolbar The Toolbar of the activity. */ public void setup(int fragmentId, DrawerLayout drawerLayout, Toolbar toolbar) { View mFragmentContainerView = (View) getActivity().findViewById(fragmentId).getParent(); DrawerLayout mDrawerLayout = drawerLayout; //noinspection deprecation mDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.colorPrimaryDark)); ActionBarDrawerToggle mActionBarDrawerToggle = new ActionBarDrawerToggle(getActivity(), mDrawerLayout, toolbar, "Drawer opened", "Drawer closed") { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (!isAdded()) return; // Solution: // Disable click event on views below Navigation Drawer mFragmentContainerView.setClickable(false); getActivity().invalidateOptionsMenu(); } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (!isAdded()) return; // Solution: // Enable click event on views below Navigation Drawer mFragmentContainerView.setClickable(true); getActivity().invalidateOptionsMenu(); } }; // Defer code dependent on restoration of previous instance state. mDrawerLayout.post(new Runnable() { @Override public void run() { mActionBarDrawerToggle.syncState(); } }); //noinspection deprecation mDrawerLayout.setDrawerListener(mActionBarDrawerToggle); } 

What he

+2
Oct 19 '16 at 12:13
source share

Ok, I found one solution for this problem. When the drawer opens, you can bring the navigation bar to the front by calling the bringToFront () method on the layout you are using. This ensures that the navigation box remains on top of any main content until a new item is selected.

i.e:

 @Override public void onDrawerOpened(View drawerView) { activity.getActionBar().setTitle("Select content"); activity.invalidateOptionsMenu(); drawerLayout.bringToFront(); } 
-one
Jul 6 '13 at 1:08
source share



All Articles