我正在尝试让自定义对话框在按下按钮时关闭
//set up dialog
Dialog dialog = new Dialog(BrowseActivity.this);
dialog.setContentView(R.layout.about);
dialog.setTitle("This is my custom dialog box");
dialog.setCancelable(true);
//there are a lot of settings, for dialog, check them all out!
//set up text
TextView text = (TextView) dialog.findViewById(R.id.TextView01);
text.setText(R.string.app_help_message);
//set up image view
ImageView img = (ImageView) dialog.findViewById(R.id.ImageView01);
img.setImageResource(R.drawable.icon);
//set up button
Button button = (Button) dialog.findViewById(R.id.Button01);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Dialog.dismiss();
}
});
//now that the dialog is set up, it's time to show it
dialog.show();
return true;
dialog.dismiss 对我不起作用。我只是想使用此自定义对话框作为帮助屏幕,并希望按下按钮将其关闭。
我对 Android 开发很陌生,但已经尝试了很多个小时
感谢您的任何建议
final Dialog dialog = new Dialog(BrowseActivity.this);
您需要小写对话框。
public void onClick(View v) {
dialog.dismiss();
}
Also AlertDialog.Builder
可能是您更好的选择。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)