I want to use navigation drawer and tabs together.I have googled it but i didn't get correct answer,even I am confused whether to use or not when i use navigation drawer I use the FrameLayout and for tab also I use FrameLayout how do i differentiate them how can I use.Can anyone explain me.Previously action bar were there but, now they are deprecated. I am using toolbar.
Thanks in advance.
I want to use navigation drawer and tabs together.
Why? Navigation Drawer gives user clickable options and when an item is selected, developer has to change the fragment in the Activity's FrameLayout.
Tab view is also an alternative, i.e. you can have all drawer options in form of 'swipe-able' tabbed fragments, using viewPager.
Now you should decide, to go with drawer or viewPager
Alternatively, if you do want to use both in your app you can go for a viewpager inside slidingDrawer. Now ViewPager will have tabbed swipe view and slidingDrawer options can open new Activities.
Let me know of your decision and then I can update here with appropriate code snippet/links.
Related
I have a project with the following 4 layouts:
I have actually 1 activity holding a bottom app bar and the NavHostFragment where the fragments get injected. The Main Fragment is the home view. There is a Management and a Setting fragment, both are top-level views like the home view but doesn't depend on each other. These 3 fragments can be switched by clicking an item in the nav drawer. For simplification, I'm trying the new navigation architecture component.
Now I have some design questions:
Should I move the bottom app bar into the fragments, cause they don't depend on each other and the FAB button has another action, otherwise I had to change the onClickListener in the activity when the fragments switch?
1.1 Or should I even show the bottom app bar in the management fragment? Maybe just the top bar with the Up caret.
1.2 Or bottom app bar + top bar and Up caret
1.3 and what about the drawer icon, should I display it in the Mgmt fragment
Should I use a fragment or an activity for the Settings fragment? When I use a fragment, I have to move the bottom app bar into the fragments. Otherwise, the bottom app bar would be visible in the Settings Fragment
The Management Fragment has just a recycler view. Clicking on an item should open a DetailView. Should I use a fragment or an activity here?
I read the doc about the navigation architecture component and there is a section about customizing the destination. Also, ich checked the source code and know that the fragments get replaced.
Further, I checked out some frequently used Apps how they implemented the navigation with a nav drawer and noticed, they all replace their fragments. Why does no one hide/show the fragments, is there a reason not to doing this?
Assume we have a fragment with a listview that holds data collected from a database or another expensive task. So wouldn't it be better to show/ hide these fragments instead of replacing it?
Sorry, it's my first app and I'm really confused about this topic, and it seems there are no official recommendations about it out there not even Material Design guidelines don't really make a reference about it.
How would you do it?
setupWithNavController on a Toolbar (or subclasses like BottomAppBar) only set up the Up icon and the title - they do not hook up menu items added to the Toolbar.
As per the Tie destinations to menu items documentation, you must set up your own listener and call onNavDestinationSelected(). For a BottomAppBar, that would be done by setting a Toolbar.OnMenuItemClickListener:
val navController = Navigation.findNavController(this, R.id.navigation_fragment)
myBottomBar.replaceMenu(R.menu.menu_with_nav_item)
myBottomBar.setupWithNavController(navController)
// Connect MenuItems to the NavController
myBottomBar.setOnMenuItemClickListener { menuItem ->
menuItem.onNavDestinationSelected(navController)
}
I have an activity that extends fragmentActivity that has a navigation Drawer, and three different fragments.
Is there a way to make a navigation Drawer that has different buttons inside each of my fragments?
For example when you enter fragment 1 you will see certain buttons in the navigation Drawer, and when you go to fragment 2 you will see different buttons in the navigation Drawer.
You should just define which options are to be displayed in the NavigationDrawer depending on which current Fragment you're on, using a switch statement or if statement.
Check out this link:
How to change fragments using Android navigation drawer
Also, from this link https://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html
As per the Android Design guide, any drawers positioned to the
left/start should always contain content for navigating around the
application, whereas any drawers positioned to the right/end should
always contain actions to take on the current content. This preserves
the same navigation left, actions right structure present in the
Action Bar and elsewhere.
So this type of thing seems like it was planned for when the NavigationDrawer was designed.
I am using bradley's navigation drawer for displaying options in a listAdapter. Now I want to change the layout and add sliding tabs in the appCompatActionBar. The attached image is what I want to achieve.
Can someone provide a tutorial link or tell me how should I modify the actionbar to draw such layout?
I want to use Navigation drawer in Action Bar and below that I want to use Swipe Tabs in single sherlock fragment. I want to open above sherlock fragment on the Item click of ListView.And Most Important think is that I want to open different swipe tab on the click of different Item in ListView.
thank in advance.
Use this library. Because Navigation Drawer with swipe tabs is really difficult and as far as I know many developers are struggling with it. For reference you can refer my Application.
Create the Navigation Drawer with the standard procedure and just integrate the above library.
Hope it helps
Does anyone successfully implemented Navigation Drawer with Fragments, Up Navigation and ActionBar?
As stated in documentation Up Navigation works automatically with Activities. But If I want to implement Navigation Drawer, then I have to use fragments.
I have set:
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
I also put all fragments to BackStack. When checking listener OnBackStackChangeListener, I see that BackStack is being checked, but the Up navigation arrow doesn't show up.
Navigation Drawer with Fragments
take a look at this question and this may also help you. As stated in the second link, you don't "have to use Fragments to use the NavigationDrawer"
Although many navigation drawer examples show how fragments can be
used with the navigation drawer, you can also use a
RelativeLayout/LinearLayout if you wish to use the drawer as an
overlay to your currently displayed Activity.
This is actually the approach I've used in one of my recent projects and it works fine.