How to disable navigation drawer of activity from within a fragment - java

I've been looking for an answer to this for a while but I haven't found any answers on the subject.
So I have my Main Activity which containers a toolbar, a nav drawer, and a frame layout (the container for my fragments). So on the start of the activity it starts a fragment to display and I can switch between different fragments and they all have the toolbar and nav drawer because their container is still main activity.
Except there is one problem. I want to make a new fragment and I don't want it to use a nav drawer or a toolbar. I figured out how to disable and hide the toolbar from within that specific fragment but I haven't been able to find out how to disable the nav drawer. The user can still swipe from left to right to open the nav drawer. I don't want them to be able to do that.
Also if I was going to disable it, I need to disable it from the fragment not the main activity because the navigation to this fragment is from a button that's inside another fragment

You can use :
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
This will lock drawer opening on swipe
Source : How to Disable drawer in fragment and back back to correct fragment

Related

How can I switch bottomnavigationview fragment to another one that is not a menu item

I have a bottom navigation view in Activity with 4 menu items (4 different fragments) that switches between them. The question is: how can I go from that menu fragment to another fragment that is not included in bottomnavigationview (deeper fragment hierarchy). I am using Android Navigation Framework to switch between fragments.
You could use a navigation drawer or tabs as well.
You can find more info here

Navigation Components: Switch Menu of Navigation Drawer (for logged in users)

I am using the new Navigation Components library. I have a Navigation Drawer in place that works perfectly fine.
If my user logs in I want to change the menu of the Navigation Drawer. Specifically, I want to change the "Login" item to "Logout" from within a fragment.
All the solutions I found online didn't use Navigation Components. So therefore, they recommended something like this:
// Get the navigationView and swap the menu
NavigationView navigationView = view.findViewById(R.id.nav_view);
navigationView.getMenu().clear();
navigationView.inflateMenu(R.menu.activity_main_drawer_logged_in);
However, this doesn't seem to work in my case (I cannot get the navigationView from within a fragment). How does one achieve this with Navigation Components?
You can access Activity from Fragment through interface:
Create and interface say LoginSuccessListener
Implements this in your Activity
Inside fragment receive this listener inside onAttach
Use it as you needed to update Navigation Menu

How can i set different onBackPressed() for different fragment of a NavigationDrawer Activity?

I I need to change the toolbar icon of my main_activity(Navigation Drawer Activity) and replace it with back icon and with a different function(go back).
How can i change different toolbar with different function for all my fragment?
I'd suggest starting a new activity instead.
This way you don't have to modify the drawer icon and touch handling of the icon is also separated. (You would just close your new activity when the up navigation is clicked).
However, if you want to do it all in your current Activity, you need to change the ActionBar / Toolbar icon and override the clickListener of the navigation icon.
toolbar.setNavigationIcon(R.drawable.ic_arrow_back);
and
toolbar.setNavigationOnClickListener(yourClickListener);

Android Navigation Drawer & Fragment with swiping Tabs

It is possible to have a Navigation Drawer and a FragmentActivity which has also swiping tabs?
E.g. When I select an item in the menu, a swiping tab view should appear.
To answer your question - yes, it is absolutely possible. Navigation Drawer Swipe Views
Just follow above tutorials and combine them.

Navigation Drawer app behaivour when open fragments

Im working with a Android app that uses Navigation Drawer. This app use the template provided with Eclipse ADT (when you select the navigation drawer template).
I dont understand the behaivour of the navigation drawer very well.
My main requeriment is make a "search" option, I have on the Navigation Drawer a EditText to get the query string from the user. I want that I press search button and open my SearchFragment getting the search query.
I know that I can make this:
Bundle args = new Bundle();
args.putString("searchQuery",searchQuery);
fragment.setArguments(args);
And this for getting:
getArguments().getString("searchQuery");
But I have the next:
MainActivity
NavigationDrawerFragment
SearchFragment
OtherFragments.. (I think this arent relevant in the question)
I dont understand where I can make this steps.
More data:
I have in the navigation drawer class the EditText with the setOnEditorActionListener for the search press.
Any info that I can add I will be add. Sorry my english
Thanks for the help
Navigation drawer is basically a component that show 2 pane in the way that one is the main pane (usually fragment) that is used to show content and the other one is usually a listview that is just used to choose which fragment to show in main pane
so if you want to switch between 2 different layouts you have to create 2 different fragments and then you can add or replace these fragments based on listview's selected item.
You may refer to below link for complete code
http://developer.android.com/training/implementing-navigation/nav-drawer.html
Hope it helps!

Categories

Resources