Last Updated: 09 Feb, 2023
In Android, there are three types of menus available to define a set of options and actions in our Android applications. The menus in Android applications are as follows:
MenusAndroid Option Menus are the primary menus in Android. They can be utilized for settings, searching, deleting items, etc. The appearance of this item as an action item in the app bar is determined by the 'Show Action' attribute. The values that can be assigned to the 'showAsAction' attribute are:
Android Option MenusShow ActionshowAsAction attributeSyntax:
<item android:id="@id/message" android:icon="@android:drawable/ic_menu_send" app:showAsAction="always" android:title="message" /> |
never: This indicates that the menu will never be displayed and will be accessible through the overflow menu.
The Options Menu in Android provides a way for users to access key functionalities and settings within an app. Let's delve into how it can be implemented effectively.
Below is the complete code for implementing the Options Menu in Android:
menu
tag.xmlns:android
, xmlns:app
, and xmlns:tools
.tools:context
attribute.The XML structure for defining the Options Menu in Android involves specifying various attributes for each menu item:
Item ID | Icon | Title | ShowAsAction |
---|---|---|---|
@id/message | @android:drawable/ic_menu_send | message | always |
@id/picture | @android:drawable/ic_menu_gallery | picture | always|withText |
@id/mode | @android:drawable/ic_menu_call | mode | always |
@id/about | @android:drawable/ic_dialog_info | calculator | never|withText |
@id/exit | exit | never |
By following these steps, you can create a functional and user-friendly Options Menu in your Android application.
The MainActivity class in Android development requires various import statements to access necessary functionalities:
The MainActivity class extends AppCompatActivity and contains various methods:
Within the onOptionsItemSelected() method, specific actions are taken based on the selected menu item:
Feeling lost in the vast world of Backend Development? It's time for a change! Join our Java Backend Development - Live Course and embark on an exciting journey to master backend development efficiently and on schedule. What We Offer:
Our comprehensive course provides in-depth learning opportunities for all participants, ensuring a thorough understanding of the subject matter.
Participants can actively engage with our platform through various means to enhance their learning experience.