gpt4 book ai didi

Android关闭自定义对话框

转载 作者:IT老高 更新时间:2023-10-28 23:10:36 24 4
gpt4 key购买 nike

我正在尝试让自定义对话框在按钮按下时关闭

        //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 dev 的新手,但已经尝试了很多小时

感谢您的建议

最佳答案

final Dialog dialog = new Dialog(BrowseActivity.this);

你需要小写的对话框。

public void onClick(View v) {
dialog.dismiss();
}

另外 AlertDialog.Builder 可能是您更好的选择。

关于Android关闭自定义对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6258162/

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