gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:15:19 26 4
gpt4 key购买 nike

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

   @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 - 从选项菜单中弹出文本对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6608880/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com