再次我有问题,我想点击一个菜单项然后它会打开一个有标题的盒子,也许是一个文本框/ btn,我怎么能这样做?
这是使用
的菜单代码public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.icon: Toast.makeText(this, "You pressed the icon!", Toast.LENGTH_LONG).show();
break;
case R.id.text: Toast.makeText(this, "You pressed the text!", Toast.LENGTH_LONG).show();
break;
case R.id.icontext: Toast.makeText(this, "You pressed the icon and text!", Toast.LENGTH_LONG).show();
break;
}
return true;
}
}
答案 0 :(得分:1)
最后在Egor的帮助下解决这个问题,这就是你如何拥有它,当你点击一个菜单项时出现一个自定义对话框
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.savefile:
showDialog(SAVE_DIALOG);
}
return true;
}
protected Dialog onCreateDialog(int id) {
Dialog dialog = new Dialog(this);
switch(id) {
case SAVE_DIALOG:
dialog.setContentView(R.layout.savedialog);
dialog.setTitle("Custom Dialog");
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("Hello, this is a custom dialog!");
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.icon);
break;
default:
dialog = null;
}
return dialog;
}
答案 1 :(得分:0)
看看AlertDialog
。这个post有一些创建对话框的好例子。希望这会有所帮助。