Hello Friends.
Follow Below Step for Create Programmatic Menu in Android.
Here Use onCreateOptionsMenu(Menu menu) Override method.
1) First Create Simple Android Project (menudemo)
2) Now edit string.xml(Path:- res/values/string.xml)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, MenudemoActivity!</string>
<string name="app_name">Menudemo</string>
<string name="HomeOption">Home</string>
<string name="Oak">a@k</string>
</resources>
Here above Code for Manualy create String Home and a@k.
3) Edit MenudemoActivity.java (this is Android Activity)
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
public class MenudemoActivity extends Activity {
/** Called when the activity is first created. */
int id_menu = 1;
@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(R.string.HomeOption);
menu.add(R.string.Oak);
menu.add("Welcome");
return super.onCreateOptionsMenu(menu);
}
}
Here in Above Code onCreateOptionsMenu(Menu menu) override method use for create menu. then use add method for add string from string.xml or manualy like "welcome"
4) Now Run Android Application.
See in Emulator after Run project Click on Menu Button and See Below Output.
Follow Below Step for Create Programmatic Menu in Android.
Here Use onCreateOptionsMenu(Menu menu) Override method.
1) First Create Simple Android Project (menudemo)
2) Now edit string.xml(Path:- res/values/string.xml)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, MenudemoActivity!</string>
<string name="app_name">Menudemo</string>
<string name="HomeOption">Home</string>
<string name="Oak">a@k</string>
</resources>
Here above Code for Manualy create String Home and a@k.
3) Edit MenudemoActivity.java (this is Android Activity)
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
public class MenudemoActivity extends Activity {
/** Called when the activity is first created. */
int id_menu = 1;
@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(R.string.HomeOption);
menu.add(R.string.Oak);
menu.add("Welcome");
return super.onCreateOptionsMenu(menu);
}
}
Here in Above Code onCreateOptionsMenu(Menu menu) override method use for create menu. then use add method for add string from string.xml or manualy like "welcome"
4) Now Run Android Application.
See in Emulator after Run project Click on Menu Button and See Below Output.
Comments
Post a Comment