Android的亲密定制对话框 [英] Android close custom dialog
本文介绍了Android的亲密定制对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让自定义对话框中关闭按钮preSS
//设置对话框
对话的对话=新的对话框(BrowseActivity.this);
dialog.setContentView(R.layout.about);
dialog.setTitle(这是我自定义对话框);
dialog.setCancelable(真);
//有很多的设置,对话框,检查他们都出来了! //设置文本
TextView的文本=(TextView的)dialog.findViewById(R.id.TextView01);
text.setText(R.string.app_help_message); //设置图像视图
ImageView的IMG =(ImageView的)dialog.findViewById(R.id.ImageView01);
img.setImageResource(R.drawable.icon); //设置按钮
Button按钮=(按钮)dialog.findViewById(R.id.Button01);
button.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(视图v){
Dialog.dismiss(); }
}); //现在的对话框设置,它的时间来显示它
dialog.show(); 返回true;
dialog.dismiss是不是为我工作。我只是想用这个定义对话框作为一个帮助屏幕,并希望有一个按钮preSS将其关闭。
我很新的Android开发人员,但一直在努力这样做对于许多许多小时
感谢您的任何意见
解决方案
最后对话的对话=新的对话框(BrowseActivity.this);
您需要小写的对话框。
公共无效的onClick(视图v){
dialog.dismiss();
}
还有 AlertDialog.Builder
可能是你更好的选择。
I am trying to get the custom dialog to close on button press
//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 is not working for me. I am simply trying to use this custom dialog as a help screen and want a button press to close it.
I'm very new to android dev but have been trying this for many many hours
Thanks for any advise
解决方案
final Dialog dialog = new Dialog(BrowseActivity.this);
You need lowercase dialog.
public void onClick(View v) {
dialog.dismiss();
}
Also AlertDialog.Builder
may be a better choice for you.
这篇关于Android的亲密定制对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文