Android – 从选项菜单中弹出文本对话框

一个简单的问题.我想要一个静态对话框消息,当按下选项菜单中的按钮时,只能弹出文本.这是我的菜单代码:

   @Override
   public boolean onOptionsItemSelected(MenuItem item) {
       switch (item.getItemId()) {
           case R.id.icon:
                Intent intent = new Intent(this, Main.class);
                startActivity(intent);
           case R.id.help:
               //popup window code here
       }
       return true;
   }
}

我最简单的方法吗?谢谢!

解决方法:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
       case R.id.icon:
            Intent intent = new Intent(this, Main.class);
            startActivity(intent);
       case R.id.help:
           //popup window code here
Toast.makeText(this, "This is the Toast message", Toast.LENGTH_LONG).show();

   }
   return true;
}
}

或者我可以使用对话框

@Override
public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
       case R.id.icon:
            Intent intent = new Intent(this, Main.class);
            startActivity(intent);
       case R.id.help:
           //popup window code here
 AlertDialog.Builder alertbox = new AlertDialog.Builder(this);

        // set the message to display
        alertbox.setMessage("This is the alertbox!");

        // add a neutral button to the alert box and assign a click listener
        alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() {

            // click listener on the alert box
            public void onClick(DialogInterface arg0, int arg1) {
                // the button was clicked

            }
        });

        // show it
        alertbox.show();

   }
   return true;
}

}

上一篇:android中的自定义微调器弹出列表


下一篇:带有可选文本的python tkinter弹出窗口