Android app Option Menu

Source: Internet
Author: User

Main Activity Java
@Override
public boolean Oncreateoptionsmenu (Menu menu) {
Getmenuinflater (). Inflate (R.menu.more, menu);
return Super.oncreateoptionsmenu (menu);
}

//This overload is designed to enable icon display in menu (Option menu icon is not displayed after 4.0)
@Override
public boolean onmenuopened (int featureid, menu menu) {
if (menu! = null) {
if (Menu.getclass (). Getsimplename (). Equalsignorecase ("Menubuilder")) {
try {
method = Menu.getclass (). Getdeclaredmethod ("setoptionaliconsvisible", Boolean.type);
if (Method! = null) {
Method.setaccessible (TRUE);
Method.invoke (menu, true);
}
} catch (Exception e) {
E.printstacktrace ();
}
}
}

Return super.onmenuopened (Featureid, menu);
}

@Override
public boolean onoptionsitemselected (MenuItem item) {
Switch (Item.getitemid ()) {
Case R.ID.MORE_MENU1: {
...
}
Break
Case R.ID.MORE_MENU2:
Break
    }
return super.onoptionsitemselected (item);
}
Menu Resouce File
<?xml version= "1.0" encoding= "Utf-8"?>
<menu xmlns:android= "Http://schemas.android.com/apk/res/android" >

<item
Android:id= "@+id/more_menu1"
android:icon= "@drawable/IC_EVENT_24DP"
Android:title= "Asset Statistics"
></item>

<item
Android:id= "@+id/more_menu2"
        android:icon= "@drawable/IC_CODE_24DP"
        android:title= "Code Trace"
></item>

</menu>



Android app Option Menu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.