8

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.

Pritam
  • 339
  • 3
  • 23
Vlad
  • 211
  • 1
  • 10
  • 1
    I dont think the bottom bar is an app bar in the way you are thinking. Just a custom view/bar with floating button. You can create a `LinearLayout` with `ImageButton` or something similar – IAmGroot Aug 24 '18 at 08:57
  • If possible can you please share the xml code?@Doomsknight – Pritam Aug 27 '18 at 08:55

2 Answers2

13

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

Vlad
  • 211
  • 1
  • 10
0

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.

ʍѳђઽ૯ท
  • 16,646
  • 7
  • 53
  • 108