Navigation Drawer disable backview when drawer open - android

I am getting a strage behaviour with my navigation drawer. I use a custom layout for it, containing not only the usual listview!
Whenever i click somehwere in the drawer section the rows from the behind listview are getting clicked. How can i disable that?
SOLUTION:
just set android:clickable="true" on the parent layout in the drawer outside the listview and it all works fine.
Thanks for your answers.

Try this in your MainAcivty with the drawer content when it's open, to disable sending touch events to parent layout
getParent().requestDisallowInterceptTouchEvent(true);

Set android:clickable="true" to the parent layout in the drawer section.

Related

Android navigation drawer reorder items

I'm facing an weird behaviour of navigation drawer so if someone can help...
I have a navigation drawer filled by an adapter (like list of Object : title and icon).
In Activity
mNavItems = NavBarUtil.listItem(); // List of object
mBinding.navList.setAdapter(new DrawerListAdapter(this, mNavItems));
The view for drawer is just a simple ListView.
The weird behaviour is that when the keyboard appears (whatever it comes), the order of the items in navigationDrawer change... it's like, displaying the keyboard recalculate all the view.
Just wanna precise that all listener for item work fine, the issue is just about the view like icon and title...
Thanks you guys

Android navigation drawer set clickable area only to list items

I am using a NavigationDrawer in my application and I am loading in the drawer a ListView. When the drawer is opened, it covers almost half of an Activity which contains also a ListView.
The problem that I face is that if I tap on the drawer(not on an item contained in the drawer), a ListView item from my Activity gets the click event and then starts an activity associated with that list item.
Is it possible to restrict the clickable area of the drawer only to the list items?
I assume your drawer layout is more complex than just a simple ListView, if you have place to tap on the drawer.
In that case, you could simple specify
android:clickable="true" for your top drawer layout (LinearLayout, RelativeLayout or whatever you use).

Navigation bar and viewpager on same activity

In my app navigation drawer and viewpager are on same activity. I want to hide viewpager on clicking the item on navigation drawer.
I tried to set its visibility as GONE but it didn't work.
Pleaseeee tell me how to hide it thanks..
Tab.setVisibility(ViewPager.GONE); this is the line I wrote in my code
On clicking drawer item fragment containing webview opens
If you want to hide the ViewPager, you need to set it's visibility to View.GONE. Try
myViewPager.setVisibility(View.GONE);
instead. Currently you're setting the visibility on a Tab and not the ViewPager itself. They're 2 completely different things.

Changing navigation drawer layouts

How to inflate new layout on custom navigation drawer when, for example, I click another button in main activity? Is that possible? I havent found any function like beforeOpenDrawer or etc. Or should I construct 4 seperate drawers?
Thank you for your answers
We managed that using fragments. Our DrawerLayout contains a FrameLayout in which we put a "menu" fragment. Some clicks replaces the "menu" fragment by a "submenu" fragment.
I'm not sure I get what you mean.. but if what you want is:
. To create a navigation drawer with custom layout (not just list view) then it is possible.
. Or if you having multiple buttons or radio buttons inside the drawer layout and you need for example to listen for their onClick events … you only write the code once inside the main activity that inflate the left or right drawer.. I've tried something like that but I was using fragments not activities.

How to hide the NavigationDrawer after item from its ListVIew is clicked?

Simple example of what i want to do - when you open Google Play app and click on the top left corner - a Navigation Drawer appears. Then if you click on any option, say "My apps" for exapmle, the Navigation Drawer hides and a new window (probably a Fragmen) appears. So how to hide it when an item is being clicked?
What i did so far:
Added <android.support.v4.widget.DrawerLayout> as a root element
of my Activity's layout. In this element i have two children - a
ViewPager for the main content, separated in few Fragments and a
ListView to load the available options.
Created ActionBarDrawerToggle and then set it to the
DrawerLayout using setDrawerListener(myDrawerToggle);
Any suggestions will be appreciated! :)
I think you create the Drawer layout in your mainactivity and you have the Variable name for List so you just use this line in your Activity......
You just declare this variable in global and just use in the activity anyware....
mDrawerLayout.closeDrawer(mDrawerList);
All the best
On ListItem click
drawerLayout.closeDrawer(drawerList);
Where drawerLayout is the drawer and drawerList is the listview.
https://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html#closeDrawer(android.view.View)
public void closeDrawer (View drawerView)
Close the specified drawer view by animating it into view.
Parameters drawerView Drawer view to close
You can download the sample app from
https://developer.android.com/training/implementing-navigation/nav-drawer.html

Categories

Resources