Home » Android » android – How to pairing bottom app bar with top app bar?

android – How to pairing bottom app bar with top app bar?

Posted by: admin June 15, 2020 Leave a comment

Questions:

In the picture what I want to do.

Pic

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.

How to&Answers:

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

Answer:

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.