26 Feb 2021

How to create Option Menu in Android Apps?


reating a Options Menu in your android a Creatingon is such an easy work that anyone can do it in single snap.How? You need to know the basic Implimentation in your app's Activity.

How to create Option Menu?

In your application super class Activity have a predefined method, To Create options menu to your app's. only need to @override and do implementation here. But How?

Public class MainActivity extend Activity {

  °°°

@Override
public boolean onCreateOptionMenu(Menu menu){ 
menu.add("About");
menu.add("Help");

return true;

}

}

Under the onCreateOptionMenu(Menu menu), call menu.add("Name") method to add menus. this method add() return MenuItem object. From which MenuItem object, you can costomise particular menu's instance.

Option Menu Selection Callback

Whenever under the Activity, Menu's item is selected/clicked, A listener or callback method is called. In this case , Activity provides you a Method -onOptionMenuSelected(MenuItem item). Need to @Override this in Activity.


@Override
public boolean onOptionMenuSelected(MenuItem item){

return true;
}


Reaction:

No comments:

No Comments

COMMENT FROM MESSAGE