package com.githang.android.actionsheet.demo;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.widget.Toast;

import com.githang.android.actionsheet.ActionSheetDialog;


public class MainActivity extends ActionBarActivity {
    private ActionSheetDialog mActionSheetDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    /**
     * 创建MENU
     */
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add("menu").setVisible(false);// 必须创建一项,设为false之后ActionBar上不会出现菜单按钮。
        return super.onCreateOptionsMenu(menu);
    }

    /**
     * 拦截MENU事件，显示自己的菜单
     */
    @Override
    public boolean onMenuOpened(int featureId, Menu menu) {
        if (mActionSheetDialog == null) {
            mActionSheetDialog = new ActionSheetDialog(this);
            mActionSheetDialog.addMenuItem("Test1").addMenuItem("Test2");
            mActionSheetDialog.setMenuListener(new ActionSheetDialog.MenuListener() {
                @Override
                public void onItemSelected(int position, String item) {
                    Toast.makeText(MainActivity.this, item, Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onCancel() {
                    Toast.makeText(MainActivity.this, "onCancel", Toast.LENGTH_SHORT).show();
                }
            });
        }
        mActionSheetDialog.show();
        return true;
    }

}

@@ -525,14 +525,58 @@
   * 
-%E5%88%9B%E5%BB%BAMENU
+Create menu, add a menu item but set it invisible.
 %0A   
@@ -788,24 +788,62 @@
   * 
-%E6%8B%A6%E6%88%AAMENU%E4%BA%8B%E4%BB%B6%EF%BC%8C%E6%98%BE%E7%A4%BA%E8%87%AA%E5%B7%B1%E7%9A%84%E8%8F%9C%E5%8D%95
+intercept the open menu event to show the custom menu.
 %0A   

Add comment to demo