How to create custom option menu in android

牧云@^-^@ 提交于 2019-12-06 08:46:19

问题


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) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.layout.overview_menu, menu);
        return true;
    }

Using the above code i am getting the all option in Same line.


回答1:


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



来源:https://stackoverflow.com/questions/7696082/how-to-create-custom-option-menu-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!