When an option menu is visible, any user action will hide it. How to prevent menu from being hidden as a result of any onTouchEvent outside menu borders ?
Use either
setGroupVisible(int group, boolean visible)
Show or hide all menu items that are in the given group.
or
setVisible(boolean visible)
Sets the visibility of the menu item.
Anyway, I think don't get exactly what you mean with menu, if this doesn't help comment and I'll give you more clues.
Related
What are the differences between Context menu vs Popup menu vs bottom sheet?
and what kind of situations they are best fit for?
Option Menu Option Menus are the primary menus of android. They can be used for settings, search, delete item etc. we are inflating the menu by calling the inflate() method of MenuInflater class. To perform event handling on menu items, you need to override onOptionsItemSelected() method of Activity class.
Context Menu Android context menu appears when user press long click on the element. It is also known as floating menu.
Bottom sheets bottom sheet is a sheet of material that slides up from the bottom edge of the screen and presents a set of clear and simple actions
Please read this SO Answer difference-between-context-menu-and-option-menu-in-android
Bottom sheet is an Android component that present anchored views at the bottom of the screen. It became popular on Android 5, you can find more information in the Material Design documentation.
Popup menu is a dialog box linked to a concrete element in the UI, with it you can implement the Quick Actions UI pattern.
⦁ Pop-up menu/context Menu - A context menu (also called contextual, shortcut, and popup or pop-up menu) is a menu in a graphical user interface (GUI) that appears upon user interaction, such as a right-click mouse operation.
⦁ Fall-down menu - move the mouse over the menu to open it. In a computer, a drop-down menu is a menu that offers a list of options. The title of the menu, of the currently-selected item in the list, is always displayed. When the visible item is clicked, other items from the list "drop-down" into view, and the user can choose from those options.
I'd like a logout button to appear on my app's action bar only on a certain layout, for example, web.xml. When login.xml is the current view, I don't want the button there. Is this possible?
I currently have the button fully functioning, by utilizing the normal main_activity_actions method, but I can't figure out how to change what ones show depending on current content view.
Inside of the Fragment or Activity that uses the web.xml layout, you would need to override the onCreateOptionsMenu(Menu menu) method. There you can inflate a menu.xml with the desired icon and properties for the button you would like in the action bar.
To receive click events from this button, you would need to override the onOptionsItemSelected(MenuItem item) then ensure that the clicked button was yours and do your logic.
More details can be found here on the Google Dev page
everyone! I have question for Android guys. Any help or suggestion will be appreciated.
So my problem:
I have application with ActionBarCompat and in this action bar I have a lot of different hiden menu items, which appear only if user click on menu button at action bar. Also I have couple menu items at action bar, which always visible.
I need some customization for one of visible menu item. When user click on this menu item (let's say it would be "Add new" menu item), I need to show different menu in this case. And if user click on standart menu item, it should act like usually.
So I really confused. And I have no idea how I can do it. Maybe someone had the same problem or similar. Thank you!
Screenshot for better understanding:
I am using Action bar and having menu items implemented using Action Provider. Clicking on menu item shows Popup Spinner. Now when any Menu item is clicked and Popup screen is ON and that time - If Overflow menu item is clicked then it doesn't show menu items under Overflow list (I need to click once again to get Overflow menu items).
Is this known issue? Is there any workaround for this?
Is this known issue?
It's known. It is not an issue. The drop-down for list navigation (what I presume the "Popup Spinner" is) has the focus. It takes a tap outside of the drop-down, anywhere in the activity, to dismiss the drop-down.
This is not significantly different than the behavior of a Spinner anywhere else in Android. For example, edit a contact, and tap on the Spinner to change a phone number type (e.g., mobile vs. home vs. work). It takes a tap anywhere else to dismiss the drop-down list, before a tap will have any other meaning.
Is there any workaround for this?
Do not use list navigation or other Spinners in your app.
I want to make Option Menu for Android, I have visit this site. In their script, I found onPrepareOptionsMenu, I try to compile and run using Android 2.3.3 compiler with and without onPrepareOptionsMenu, both works, but I didn't see any difference.
public boolean onCreateOptionsMenu(Menu menu){
//code here
}
public boolean onOptionsItemSelected(MenuItem item){
//code here
}
public boolean onPrepareOptionsMenu(Menu menu){
//code here
}
What is actually onPrepareOptionsMenu method do? Is that method important? Could I just delete the method?
Addition
Oh, I also hear about Action Bar in Android 3.0, it says that Action Bar is the alternative way for make Option Menu, and it using onPrepareOptionsMenu. Is that right?
Thank you...
Take a look in the API:
Prepare the Screen's standard options menu to be displayed. This is called right before the menu is shown, every time it is shown. You can use this method to efficiently enable/disable items or otherwise dynamically modify the contents.
If you want to alter the menu before it's shown to the user, you can put code to do that into onPrepareOptionsMenu. I've used that dynamically to disable some menu options in some circumstances.
As an example of when one might want to disable a menu option, I had an app where there was a way of specifying a destination. One of my menu options was to calculate a route to the destination. However, if a destination wasn't specified, that option didn't apply, so I used onPrepareOptionsMenu to disable that menu option when it wasn't applicable.
From Android 3.0 and beyond, there's the ActionBar, which is a menu bar. The most important items go into the ActionBar itself, but then there's an overflow for when there's not enough room on the action bar. One can specify that menu items should always be in the overflow menu and never on the action bar itself. On some devices, the action bar overflow corresponds to the permanent menu button on the device, whereas on other devices which don't have a menu button the overflow menu is seen on the right hand side of the action bar as three vertical dots.
onCreateOptionsMenu is called once, when your activity is first created. If it returns false, no option menu is shown and onPrepareOptionsMenu is never called.
If onCreateOptionsMenu returns true, onPrepareOptionsMenu is also called before the activity is displayed, and also every time the options menu is invalidated. Use onPrepareOptionsMenu if you need to enable/disable, show/hide, or add/remove items after creating it.
If your menu does not change, use onCreateOptionsMenu.
example
#Override
public void onPrepareOptionsMenu(#NonNull Menu menu) {
super.onPrepareOptionsMenu(menu);
if(!URLUtil.isValidUrl(news.geturl())){
menu.findItem(R.id.share).setVisible(false);
}
}