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.
Related
Here is a screenshot of the toolbar. It has three navigation items to the left which looks just like a tab-layout. When you select the third tab, a menu item pops up from right side of the toolbar.
How can i achieve this look? Is this a tablayout inside a toolbar? Or a tablayout and a toolbar next to each other? I've tried some stuff but failed.
I would use TabBarView. Then, in the Fragment you want a MenuItem to show (like the last tab in Periscope), add setHasOptionsMenu(true) and have the MenuItem's visibility be app:showAsAction="always". Wally also uses this UI pattern.
I am implementing Navigation Drawer in my Main Activity. When I load a fragment for the drawer item, the action bar gets overlapped above the fragment.I am required to give a top margin of about 48 dp, so that my views come below the action bar. How can I bring my fragment layout below the ActionBar?
layout_marginTop="?attr/actionBarSize"
use this in your layout it changes in size based on screen configuration automatically
Have a look at this tutorial:
android-sidebar-navigation-drawer-with-icons
I want to have two menus in my android app. First one is search icon in ActionBar (at the top) and second is a TextView and pop up item at the bottom. How to achieve it? I tried android:uiOptions="splitActionBarWhenNarrow" but it moves all the menu items to bottom. Please help!
Android has not made this possible on purpose, the action bar at the bottom (called the split action bar) only has the purpose of giving extra room for actions if it is necessary (hence the uiOptions name "splitActionBarWhenNarrow").
You could still get the desired result by manually creating a split action bar by adding a LinearLayout at the bottom of your View, and using a PopupMenu for the menu.
I am using both actionbarsherlock and slidingmenu objects
the point is, I want my menu - which is sliding to do the following
push the currently visible screen aside, along with its actionbar
the fragment that is displayed inside the menu to have a different actionbar
how do i do that?
I've set everything to make 1 work
but the fragment is missing the menu - how to add it ?
You can't have multiple ActionBar in the same activity.
Best thing you could probably do, is not make the ActionBar slide with the menu, while starting/finishing an ActionMode when you open up/close the sliding menu.
Or if you really want to slide the ActionBar, then simply create a view in the menu fragment that will looks like an action bar.
You probably can use a custom layout in your actionbar and manipulate it by adding an animation so that it looks like the actionbar slides out and it is pushed by another actionbar when the menu slides in. The object would be the same, but the user perception will be of a sliding action bar pushing away the previous one.
I'm trying to make a feature where there's a button on the bottom action bar, and once I click on it, a progress bar appears on top of the button and makes the button slightly transparent (not disappear).
I used a custom layout for the top action bar, so on the bottom action bar, I wrote it through menu.xml since I've hard I couldn't have a second custom layout. I was wondering if this feature was possible just from the menu item properties.
Is it possible to make some form of like a frame-layout just from the menu.xml?
I'm assuming you're using a split action bar (uiOptions="splitActionBarWhenNarrow"), so that the custom layout you use is on the top with the application icon? The bottom bar is the menu items contained in an XML?
If this is the case, you can specify a custom layout for a menu item by using the layout attribute on the item. You could make a layout which has both items on top of each other (initially the button is VISIBLE with no alpha and the progress is GONE), then set up a click handler on the item in the onPrepareOptionMenu to set the alpha on the button to make it semi-transparent and change the visibility of the progress bar to VISIBLE.
I believe in the case where you use a custom layout, you can't use the id of the menu item for click handling (onMenuItemClicked), so you'd have to register a click listener either programatically or through the XML onClick attribute.
I apologize if any of the API calls are not 100% correct. I'm doing this mostly from memory.