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.
Related
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 am using a BottomSheet in my application, which contain some list items, and I am also using a Tab bar view in my whole application (at bottom of screen).
Is it possible and how can I display my that Tab Bar still in bottom of screen, and BottomSheet should also appear (on defined offset), but below my Tab Bar.
How can I adjust and arrange these layouts?
Please show Below link. Also you can add multiple tab bar in bottom layout.
https://material.io/design/components/bottom-navigation.html
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 working on an Android application where I have to design a menu which will populate from the action bar, like this:
I have tried my best but was not able to produce it using the Android controls.
The solutions I have tried are:
With Actionbar, add a menu item with a group with selectable="all", that produces the layout I need but when I click a checkbox for selecting it, the whole menu hides and selection is not done, moreover the menu icon in actionbar does not have the bottom right white arrow.
Tried creating a custom ActionProvider and added the menu items using class's OnPrepareSubMenu method but had the same issue.
I just need a push in the right direction and I can do the rest, suggestions are more than welcome.
Thank you :)
Use popupWindow.
In that you can make any custom layout and set it as content of your popupwindow and also you can specify an ANCHOR in your case it would be
R.id.your_menu_item
set a listener and listen the changes.
I'm using ActionBarSherlock and creating a custom ActionProvider. When clicking on the custom action provider, I've managed to make the topmost LinearLayout clickable and set a custom selector on it.
The problem is that compared to simple menu item with an icon, the custom action provider doesn't use the selector to highlight the action bar entirely from top to bottom. A few pixels on top and bottom are not being highlighted.
There is probably an elegant solution to make the entire custom action provider behave like a simple clickable menu item with an icon. Any help will be greatly appreciated.
I figured it out. Instead of using an Action Provider, I used the actionLayout for the menu item and made it clickable as shown in this post.