I am creating an option menu. it has three option HOME, EMAIL, VISIT. All three options coming at the same row. i have to show HOME option above and rest two below to Home Option(according to attached Screen Shot).
Any Ideas?? Thanks.
Here is my XML file.
<menu android:id="@+id/new_game"
android:icon="@drawable/red_no_bg"
android:title="Home" />
<item android:id="@+id/email"
android:icon="@drawable/red_no_bg"
android:title="Email" />
<item android:id="@+id/help"
android:icon="@drawable/red_no_bg"
android:title="Visit Microsite" />
</menu>
Here is my code.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInfla开发者_如何学Pythonter inflater = getMenuInflater();
inflater.inflate(R.layout.overview_menu, menu);
return true;
}
Using the above code i am getting the all option in Same line.
You can Create in two ways
1.Statically.
2.Dynamically.
Am explaining the easiest method of adding menus.
Step 1: Create a new Android Application.
Step 2: After onCreate()
method write onCreateOptionMenu();
Step 3: In onCreateOptionMenu()
Write these lines
menu.add(11, 21, 1, "Gowtham").setIcon(R.drawable.ic_launcher);
Here "Gowtham" is title of your menu item You can Home
&Email
use instead of "Gowtham".
Ans use Any images Instead of ic.launcher
精彩评论