Questions tagged [android-menu]

Questions regarding designing, implementing and handling menus and action bars in Android. A menu is a user accessible list of commands that typically provide additional functionality that may not be core to the generally displayed user interface.

Introduction

Many Android devices (prior to Android 3.0) have a hardware menu button. When the menu button is pressed, a list of additional user commands are made visible for the user to select from. Menu Items allows for both text and icons.

Android 3.0+ devices utilize an on screen menu called the action bar. In contrast to the normal menu, users do not press a hardware menu button to display the options. In fact, many devices using 3.0 have removed the hardware button entirely. In Android, the menu and action bar serve the same purpose. When developed correctly, both may be supported using similar Java code and/or combined Android XML.


Using Android XML

Android XML provides the ability to separate menu design from actual implementation. While this may be tweaked in code, or handled completely with Java, the menu XML is a valuable resource.

Android Menu Handling

There are three primary methods for handling the menu, regardless of how it is designed. These will work on an Android 3.0+ device for supporting the action bar's basic functionality.

  • onCreateOptionsMenu() - This event is fired when the user presses the Menu button for the first time. If the device is Android 3.0+, this will create the Action bar.
  • onPrepareOptionsMenu() - This event is fired when the Menu is actually opened. If this is the first time the button is pressed, it will fire immediately after onCreateOptionsMenu()
  • onOptionsItemSelected() - This event is fired whenever a user chooses a MenuItem from the menu. This event fires in Android 3.0+.
  • onCreateContextMenu()
  • onContextItemSelected()

Action Bar Handling

The native Action Bar utilizes the same methods as the Menu. For extra functionality, the Action Bar also adds the following interfaces to be implemented:

  • TabListener - enables Tabs in the ActionBar
  • OnMenuVisibilityListener - allows objects to respond to Menu visibility
  • OnNavigationListener - allows set up of navigation modes using Action Bar

Additional Links and Information

Development Guides API References Samples
1268 questions
-2
votes
1 answer

android menu code not working

I have been trying to figure out why my boolean is not changing when I press the button, when I changed it manually it worked, but it doesn't do any thing. I have tried to follow tutorials to the word but they don't work. Can anybody point out where…
jcw
  • 5,132
  • 7
  • 45
  • 54
-3
votes
1 answer

How can I create an animated tap bar in Android Studio?

I have an iOS app and I included this library from this link GitHub. I'm going to develop the same app for Android Studio, but where do I start or where to get something like this?
Salar Pro
  • 43
  • 5
-3
votes
1 answer

How to remove the menu name from the action bar?

How can I set a custom title for my action bar/toolbar ? I am using android:theme="@style/AppTheme.NoActionBar".
-3
votes
1 answer

Error:(6) error: XML or text declaration not at start of entity

My android project gives this error while I'm trying to build it.I found several solutions which tell me to remove whitespace initially. But unfortunately, I don't have any whitespace. So can you please let me know why my error occurred and possible…
Tanvir Durlove
  • 142
  • 1
  • 10
-4
votes
2 answers

Other items in action bar?

I want to put a check mark on my action bar instead of the 3 dots menu. The activity will then be finished after the check is clicked. How can I achieve this?
Steven
  • 13
  • 3
-4
votes
3 answers

Can't inflate the menu

I am going to inflate a menu in my first Activity. @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main, menu); return true; } The R.menu.main:
zhan
  • 85
  • 1
  • 1
  • 9
-4
votes
1 answer

How to add menu item from java class

I have made a menu.. it apper after clicking on button and when I click on the menu item.. the title of that Item shows in textView.. but I want give the user the ability to add new menu item.. so how can I creat new menu item from java class ? I…
-4
votes
1 answer

Alert Dialog for a drawable

I already have an onOptionsItemSelected(MenuItem item) for a submit button. In the switch(item.getItemId()){ case R.id.submit: I want an alertDialog. How may I do that. This submit is the id for the image in the res>drawable folder. So how can I…
Pramod Setlur
  • 811
  • 1
  • 15
  • 27
1 2 3
84
85