android-如何关闭AlertDialog.Builder对话框

article/2025/10/31 15:29:38

android-如何关闭AlertDialog.Builder对话框

前言
在实际写代码的时候,AlertDialog.Builder的使用算是比较频繁的,在对AlertDialog.Builder关闭的时候,我们会发现,AlertDialog.Builder对话框没有相对应的finish()或者dismiss()这样的方法可使用。

那么我们在关闭的时候怎么才能做到呢?

##AlertDialog
父类AlertDialog有dismiss方法,可以实现对话框的关闭,而且AlertDialog.Builder在.show()的时候会得到一个AlertDialog对象,用dismiss方法将该Builder关闭。

##自定义的AlertDialog.Builder布局示例
这里写图片描述

/*** 设置dialog的出现* @param hangTag*/private void showCustomizeDialog(HangTag hangTag) {final AlertDialog.Builder customizeDialog = new AlertDialog.Builder(getActivity());customizeDialog.setCancelable(false);View infoview = LayoutInflater.from(getActivity()).inflate(R.layout.wr_dialog_hangtag_info,null, false);TextView exchangeName, volume, marketPirce, region, irrigation, administrative, watertype,exchangeTime;Button backColse;exchangeTime = (TextView) infoview.findViewById(R.id.exchange_time);exchangeName = (TextView) infoview.findViewById(R.id.exchangeName);volume = (TextView) infoview.findViewById(R.id.volume);marketPirce = (TextView) infoview.findViewById(R.id.marketPirce);region = (TextView) infoview.findViewById(R.id.region);irrigation = (TextView) infoview.findViewById(R.id.irrigation);administrative = (TextView) infoview.findViewById(R.id.administrative);watertype = (TextView) infoview.findViewById(R.id.watertype);backColse = (Button) infoview.findViewById(R.id.back_colse);exchangeTime.setText(hangTag.getGprq()+"");exchangeName.setText(hangTag.getName());volume.setText(hangTag.getSl() + "");marketPirce.setText(hangTag.getJg() + "");region.setText(hangTag.getSzdq());irrigation.setText(hangTag.getSzgq());administrative.setText(hangTag.getSzglq());if (hangTag.getWaterType() == 8101) {watertype.setText("地下水");} else if (hangTag.getWaterType() == 8100) {watertype.setText("地表水");}customizeDialog.setView(infoview);final AlertDialog dialog = customizeDialog.show();/*** 返回*/backColse.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {dialog.dismiss();}});}

以上就是全部内容,仅做笔记,不喜勿喷!

在这里插入图片描述


http://chatgpt.dhexx.cn/article/hfoXiols.shtml

相关文章

Android 自定义AlertDialog

Android 自定义popuWindow 对于项目需求中,系统的弹出框不能满足我们的需求,就只能通过自定义布局来实现自己相对应的功能,这里总结一篇关于AlertDialog的 具体操作 这里把弹出框封装了一个方法,使用的时候,只需要在…

Android进阶之AlertDialog自定义

AlertDialog的自定义方式有很多种,这里介绍两种。 第一种是比较简单的,只自定义内容。 在AlertDialog使用详解中,非常详细的介绍了以下六种使用方法。 一、简单的AlertDialog(只显示一段简单的信息,比如about us&…

Android入门第九篇之AlertDialog

本文来自http://blog.csdn.net/hellogv/ ,引用必须注明出处! 时隔一年,又要准备做Android的开发了,最近复习和整理一下Android的知识。这次要说的是AlertDialog,这种对话框会经常遇到。AlertDialog跟WIN32开发中的Dial…

对话框AlertDialog的基本使用(新手)

AlertDialog是点击某一组件时,本文用按钮举例,弹出一个对话框,供你选择接下来的操作。 基础用法 首先要给按钮设置点击事件,然后再onClick里构建 AlertDialog.Builder 方法 代码如下: findViewById(R.id.btn).setOn…

Android的 AlertDialog自定义布局与常用布局用法(弹窗)

1.直接上效果图,看看是不是你们想要的效果图 2.主活动MainActivity2的代码如下 import androidx.appcompat.app.AppCompatActivity; import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; import android.app…

AlertDialog详解

对话框介绍与示例 对话框在程序中不是必备的,但是用好对话框能对我们编写的应用增色不少。采用对话框可以大大增加应用的友好性。比较常用的背景是:用户登陆、网络正在下载、下载成功或者失败的提示,还有,比如:短信来了…

Android的AlertDialog详解

转自:http://www.2cto.com/kf/201205/131876.html 参考文章:http://www.cnblogs.com/jiezzy/archive/2012/09/20/2694917.html http://blog.csdn.net/lizzy115/article/details/6924416 AlertDialog的构造方法全部是Protected的,所以不能直接…

AndroidStudio中AlertDialog的四种用法

目录 1.默认样式 2.单选弹出框 3.多选弹出框 4.自定义弹出框 补充!! 1.默认样式 android.support.v7.app.AlertDialog.Builder builder new android.support.v7.app.AlertDialog.Builder(AlertDialogActivity.this); builder.setTitle("请回…

Android之AlertDialog的基础使用

坦白说,AlertDialog我在工作中用得并不多,因为AlertDialog的样式比较固定和呆板,为了和App的整体设计匹配,一般都是使用自定义的Dialog,只有在要求不高时用一下。但是作为Android的基础控件之一,掌握它是十…

安卓AlertDialog弹窗

Android在开发中经常会遇到有弹框的需求。 经常使用的有Dialog 弹框,Window弹框(任意位置弹出除了外观样式和显示的位置的区别之外,他们之间最本质的区别是: dialog是非阻塞式对话框,popupwindow是阻塞式对话框。也就…

AlertDialog对话框的简单使用

目录 一、对话框的创建 二、单选的对话框 三、多选的对话框 一、对话框的创建 一般的对话框分为标题、内容、按钮三大部分。 常见的方法: 方法功能setTitle()设置对话框的标题setIcon()设置对话框的图标setMessage()设置对话框的提示信息setPositiveButton()设…

alertDialog使用详解

1、设置标题、内容、图标 2、设置按钮 3、使用列表、单选和多选。适配 4、设定弹窗大小 5、自定义view 6、设置点击周边灰色区域弹窗不消失 7、自定义view圆角消除周边白块 1、设置标题、内容、图标 AlertDialog alertDialog new AlertDialog.Builder(this) .setTit…

AlertDialog6种使用方法

AlertDialog 1.AlertDialog的6种创建模式 1.1setMessage 1)Java代码 //1.创建构造器AlertDialog.Builder buildernew AlertDialog.Builder(this);//2.设置参数builder.setTitle("弹窗提示").setIcon(R.mipmap.boy).setMessage("选择你的性别&#xf…

Android的AlertDialog详解(7种方式)

需要注意的两点: 1. 在setIcon时,需要使用setTitle方法,否则icon不会显示 2.如果同时调用setMessage 和 setItems(或者setSingleChoiceItems setMultiChoiceItems)函数会导致dialog没有显示内容 AlertDialog的构造方法全部是Protected的&am…

AlertDialog(对话框)详解

AlertDialog可以在当前的界面上显示一个对话框,这个对话框是置顶于所有界面元素之上的,能够屏蔽掉其他控件的交互能力,因此AlertDialog一般是用于提示一些非常重要的内容或者警告信息。 1.创建AlertDialog 首先,我们来了解一下Al…

andoid小游戏开发

apk下载:apk下载:http://download.csdn.net/detail/xiangqiao123/3805861 这是去年用android写的一个小游戏, 我感觉不错,是从事android小游戏开发入门不错的案例, 今天就把它拿出来和大家共享一下。 程序截图&a…

android 2D 游戏的开发的方法

最近学习了android 2D 应用的开发,拿来和大家分享一下,学习2D 开发前我们先了解一下SurfaceView的使用以及贴图技术的使用,最后呢,是一个简单的2的游戏的实现。 1.SurfaceView的一些用法 提供了一个专门的绘图渲染的图形嵌入在一个…

Android手机游戏开发入门教程

Android手机游戏开发入门教程 视频欣赏地址 来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29597077/viewspace-1139520/,如需转载,请注明出处,否则将追究法律责任。 转载于:http://blog.itpub.net/29597077/vie…

Android 游戏开发速递

作者 / Greg Hartrell, Head of Product Management, Games on Android & Google Play 在今年 3 月举行的 Google 游戏开发者峰会上,我们分享了 Google 为帮助游戏开发者而持续投入研发的数种新工具和服务。这些新工具和服务能够帮助游戏开发者更轻松地查看其 A…

游戏开发相关

游戏开发—图形图像篇 游戏开发--开篇  记得我第一次玩的PC game 是KKND(绝地风暴),当时的游戏平台是DOS,我只是觉得很好玩,经常和几个小学同学一起厮杀到12点。可是现在回忆起来,KKND无论是从智能设计还是在游戏画面与操作上都…