Example usage for android.app Activity onCreateOptionsMenu

List of usage examples for android.app Activity onCreateOptionsMenu

Introduction

In this page you can find the example usage for android.app Activity onCreateOptionsMenu.

Prototype

public boolean onCreateOptionsMenu(Menu menu) 

Source Link

Document

Initialize the contents of the Activity's standard options menu.

Usage

From source file:com.vuze.android.remote.AndroidUtilsUI.java

public static boolean popupContextMenu(final Activity activity, String title) {
    MenuBuilder menuBuilder = new MenuBuilder(activity);

    if (title != null) {
        try {//from   w  w w  .j  a  v  a2s. c  om
            Method mSetHeaderTitle = menuBuilder.getClass().getDeclaredMethod("setHeaderTitleInt",
                    CharSequence.class);
            if (mSetHeaderTitle != null) {
                mSetHeaderTitle.setAccessible(true);
                mSetHeaderTitle.invoke(menuBuilder, title);
            }
        } catch (Throwable ignore) {
        }
    }

    if (!activity.onCreateOptionsMenu(menuBuilder)) {
        return false;
    }

    activity.onPrepareOptionsMenu(menuBuilder);

    menuBuilder.setCallback(new MenuBuilder.Callback() {
        @Override
        public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
            return activity.onOptionsItemSelected(item);
        }

        @Override
        public void onMenuModeChange(MenuBuilder menu) {

        }
    });

    MenuDialogHelper menuDialogHelper = new MenuDialogHelper(menuBuilder);
    menuDialogHelper.show(null);

    return true;
}