First we will create Simple Option menus as Follows Steps
Download Android Option Menu: Project
For more Menu with Action we will see in following posts:
Download Android Option Menu: Project
- Create a new Android Project Name MenuDemoWithoutXml
- Override
the onCreateOptionMenu() Method in the Activity class files where you want to
add menu. From
- Right click in Activity file
- \Select ”Source”
- Select “Override / Implement Methods “
- Select “onCreateOptionMenu()” method
- Say Ok.
- Adding Menu Items into by following code
package com.menu;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
public class MenuDemoWithoutXmlActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
menu.add("Item 1").setIcon(android.R.drawable.btn_dialog)
.setIntent(new Intent(this, ActivityA.class));
menu.add("Item 2").setIcon(android.R.drawable.btn_minus);
menu.add("Item 3").setIcon(android.R.drawable.btn_star_big_off);
return super.onCreateOptionsMenu(menu);
}
}
For more Menu with Action we will see in following posts:
- Android Option Menu using Xml file: How Create with Example
- Grouping the Menu Item Why Required to Group.
- Android Content Menu using XML file : How Create With Example.

This comment has been removed by the author.
ReplyDelete