首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android close自定义对话框

Android close自定义对话框
EN

Stack Overflow用户
提问于 2011-06-07 05:21:23
回答 2查看 35.6K关注 0票数 21

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

代码语言:javascript
复制
        //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非常陌生,但我已经尝试了很多很多小时了

感谢您的建议

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-06-07 05:24:07

代码语言:javascript
复制
final Dialog dialog = new Dialog(BrowseActivity.this);

你需要小写的对话框。

代码语言:javascript
复制
public void onClick(View v) {
   dialog.dismiss();
}

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

票数 34
EN

Stack Overflow用户

发布于 2014-04-16 18:33:27

您可以在对话框中调用dismiss();。这对我很有效。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6258162

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档