I have implemented a sliding menu navigation in my app like in this picture.
When the user clicks an item in the sliding menu, a Fragment is created for the corresponding menu entry and it replaces any existing fragment. When the used navigates further away, for example, the top level Fragment is a ThingListFragment for a list of thigs, and he taps one to open a ThingDetailFragment, then I want to replace the sliding menu icon with an icon of a back arrow (so the user must first go back to the top level either by this button or by hardware back button before being able to access the menu).
At this moment I'm setting this manually and it's time consuming and error-prone if I have a lot of fragments like this.
Is there some clever way to achieve this?
Try to make a basic fragment class (for exaple: FragmentBasic) where you register your action bar icons, and then every fragment who needs these icons, extends your FragmentBasic class. after this just implement the extra layout you want
Related
I have a jetpack navigation graph setup with bottom navigation and an action bar. The bottom navigation has 3 tabs. 1 of these tabs has a detailed fragment that I would like to display the back-arrow on in the action bar.
In MainActivity onCreate(), I've added:
supportActionBar?.setDisplayHomeAsUpEnabled(true)
This displays the back button on every tab & fragment.
How can I prevent display of the back button unless the user is navigated to a non-top level fragment? Is there a method that detects when this particular navigation has occured? If so, I presume I can do something like supportActionBar?.setDisplayHomeAsUpEnabled(false)
Additionally, is there a way I can display a custom back arrow on the child pages? The default arrow does not fit the UI.
Happy to provide more detail if needed.
You could use a combination of setupWithNavController(BottomNavigationView,NavController) and setupActionBarWithNavController(AppCompatActivity,NavController,AppBarConfiguration) from NavigationUI. The first will bind the bottom navigation to the navigation controller, the second will set up the support action bar to regard the navigation.
With the AppBarConfiguration.getTopLevelDestinations() you will be able to configure when to display the back arrow. The default is to only regard the root of the navigation graph as a top level destination, but you can also use another builder to define a set of top level destinations.
I have a problem...I am developing an app in android studio.In the meantime,there is already a navigation drawer in it.But the problem is, it only appears in the home screen.When it goes to another screen, the navigation drawer is not shown. I am new to android studio but i know some of Java languages.Can anyone help me with providing anything that would help me make the navigation drawer show in all of slides and pages in my app.
from docs
Navigation Drawer
The navigation drawer is a panel that displays the app’s main
navigation options on the left edge of the screen. It is hidden most
of the time, but is revealed when the user swipes a finger from the
left edge of the screen or, while at the top level of the app, the
user touches the app icon in the action bar.
for achieve what you asked you have to use Fragments
Fragment represents a behavior or a portion of user interface in an
Activity. You can combine multiple fragments in a single activity to
build a multi-pane UI and reuse a fragment in multiple activities. You
can think of a fragment as a modular section of an activity, which has
its own lifecycle, receives its own input events, and which you can
add or remove while the activity is running (sort of like a "sub
activity" that you can reuse in different activities).
see this examples for more details
1. Navigation Drawer - android hive
2. Navigation Drawer exp 2
3. Navigation Drawer exp 3
Refer this answer also
Answer
You have to add fragments in that activity where the navigation drawer exist. Whenver the user will click on the option in the navigation drawer the view should be changed by replacing with the required fragment.So by using the fragments user will stay on the same activity but just the views will be changed in that activity. you can refer to the fragments documentation provided by android developers. https://developer.android.com/guide/components/fragments.html
I have my MainActivity that contains a navigation drawer with items. When I click on an item,it opens up a new activity. This activity has its own layout file. I want to call the navigation drawer in this activity as well. How do I do that? Because I want to navigate through the app using the navigation drawer,rather than pressing back button all the time.
Let's say I have 2 activities, both of which I want to have the Navigation Drawer. In the layout.xml for each, I specified a DrawerLayout with the appropriate list view to hold my navigation options. Essentially, the Navigation drawer is made every time I switch between activities, giving the appearance that it is persisting. To make life a lot easier, I took the common methods required to set up the navigation drawer and put them in their own class: NavigationDrawerSetup.java. That way my activities can use the same custom adapter, etc.
Complete Reference : NavigationDrawer with Multiple Acivities
I have an app in which I would like a slide out menu. It would not be in control of all the apps settings, just a simple menu with a few options. I will still have a settings menu so I don't want to get rid of that. I would like to activate the slide menu with an icon in one of the corners of the app. On the button click I would like to slide out this simple menu (not settings).
Should I use the Navigation Drawer? My first thought is no since I am not controlling any sort of navigation from within this slider. Navigation Drawer also has some default behaviors that I am not sure you can override, i.e. slide from left side of screen to access, click app icon to access, click settings menu to access.
Am I supposed to use a Navigation Drawer and try and override a bunch of behavior or is there another android pattern that I can use?
I have a list fragment, which contains a list of items. When I tap on some of the items, the navigation mode changes from NAVIGATION_MODE_STANDARD to NAVIGATION_MODE_TABS and two tabs will appear. I want the navigation mode to change back to standard (with both tabs removed) when I press on back button. However, I cannot find to place to put addToBackStack() and thus unable to implement this navigation. Could someone give me some suggestions?
Many thanks in advance