1

当我按菜单显示我的方法时有可能吗?

当我按下设备中的菜单时,我只想显示并关闭此对话框 dialog

这个方法菜单播放

private void menuplay(){
       final Dialog dialog = new Dialog(this,R.style.Theme_Dialog_costum01);
       dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
       dialog.setContentView(R.layout.dialog_play);
       dialog.findViewById(R.id.button_play).setOnTouchListener(
               new OnTouchListener() {
                   public boolean onTouch(View v, MotionEvent event) {
                       dialog.dismiss();
                       //do method
                       return true;
                   }
               });
       dialog.findViewById(R.id.button_highscore).setOnTouchListener(
               new OnTouchListener() {
                   public boolean onTouch(View v, MotionEvent event) {
                       dialog.dismiss();
                       highscoreview();
                       return true;
                   }
               });
       dialog.findViewById(R.id.button_hint).setOnTouchListener(
               new OnTouchListener() {
                   public boolean onTouch(View v, MotionEvent event) {
                       dialog.dismiss();
                       hint();
                       return true;
                   }
               });
       dialog.findViewById(R.id.button_about).setOnTouchListener(
               new OnTouchListener() {
                   public boolean onTouch(View v, MotionEvent event) {
                       dialog.dismiss();
                       aboutview();
                       return true;
                   }
               });
       dialog.show();
   }

我正在尝试这个但不工作

 @Override
   public boolean onCreateOptionsMenu(Menu menu) {
      menuplay();
      return true;
   }
4

2 回答 2

0
@Override
public boolean onCreateOptionsMenu(Menu menu) {

    getSupportMenuInflater().inflate(R.menu.menu_main, menu);
    menuplay();
    return super.onCreateOptionsMenu(menu);
}
于 2013-07-22T11:35:00.317 回答
0

将此用于Menu Button

public boolean onKeyDown(int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_MENU && event.getAction() == 0 ) 
{
   menuplay();
   return true;

 }
于 2013-07-22T12:31:31.467 回答