I'm trying to add navigation bottom bar with 4 activities(each activity has each layout xml files) to swith with tab the bottom bar. I saw some examples and tutorials, they implement navigation bottom bar with fragment activites. I have already made all activites(including google map), when I tried to switch FragmentActivity to Fragment, it causes lots of errors.
SO, does navigation bottom bar only works with Fragment?
Related
I have a main activity with bottom nav and a frame layout to hold each fragment I have made for the numbers of icon in my botton nav. I have a fragment page in which i have a text and want to change the fragment and also the bottom nav icon from the click action on text.
Please refer to below links :
Android new Bottom Navigation bar or BottomNavigationView
How to Code a Bottom Navigation Bar for an Android App
Android Working with Bottom Navigation
In the picture what I want to do.
I have two menu.xml files. How to add the first menu at top app bar and the second at the bottom app bar? Can I do this in one activity or I should create activity with top app bar + fragment with a bottom app bar? Thanks.
So, I solved this problem.
For toolbar on top of the activity I use setSupportActionBar() inflate menu in onCreateOptionsMenu() and processing MenuItem click in onOptionsItemSelected()
For BottomAppBar (new material component) I use bottomAppBar.replaceMenu() in order to set the menu. For processing MenuItem click: bottomAppBar.setOnMenuItemClickListener()
Result
How to add the first menu at top app bar and the second at bottom app
bar? Can I do this in one acivity or I should create Activity with top
app bar + fragment with bottom ap bar?
You'll probably be able to do that with onCreateOptionsMenu() for the top of the Activity, (called Toolbar) then use a NavigationDrawer and another View (Can be a custom view like LinearLayout with ImageViews or etc) or another Toolbar in the bottom.
Or, using custom view and inflating menus by onCreateOptionsMenu().
This might help for two Toolbars in one Activity: https://stackoverflow.com/a/37002188/4409113
Also: https://stackoverflow.com/a/34906999/4409113
In your case (as we can see in the picture), i believe there is a Toolbar at top of Activity, with CoordinatorLayout which has FloatingActionButton in the middle and there will be just inflating in java-kotlin side left.
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.
How do I hide the ActionBar as a user scrolls down a View?
I just created a sample activity from Android Studio's default "Tabbed Activity" using navigation style "Action Bar Tabs (with ViewPager". From there, if a user swipes down one of the tabs, how can I implement that effect of hiding the ActionBar and then pulling it back down when the user scrolls up? (Just like Google Play app does).
EDIT:
One of the tabs has a RecyclerView with some Views inside. It scrolls vertically. So you can read this as: how to hide the ActionBar as I scroll down this RecyclerView?
EDIT 2:
Visually, I'm trying to achieve this:
try this
getSupportActionBar.hide(); // if it extends action bar activity
or
getActionBar.hide();