Android 简易的自定义确认弹框AlertDialog
使用方式/构造函数参数解释:
参数一:上下文; 参数二:标题; 参数三:内容; 参数四:确认按钮点击回调
CustomDialog(this, "清空输入", "确定要清空已输入内容吗?", object : CustomDialog.ClickCallBack {override fun onYesClick(dialog: CustomDialog) {//点击确认按钮后具体操作dialog.dismiss()}}).show()
自定义Dialog代码:
/*** Created by Xinghai.Zhao* 自定义选择弹框*/
@SuppressLint("InflateParams")
class CustomDialog(context: Context?) : AlertDialog(context){var mCallBack: ClickCallBack? = nullvar mTextViewTitle: TextView? = nullvar mTextViewContent: TextView? = nullconstructor(context: Context?, title: String?, content: String?, callBack: ClickCallBack) : this(context) {mCallBack = callBackif (title != null) mTextViewTitle?.text = titleif (content != null) mTextViewContent?.text = content}init {val inflate = LayoutInflater.from(context).inflate(R.layout.dialog_custom, null)setView(inflate)//设置点击别的区域不关闭页面setCancelable(false)mTextViewTitle = inflate.findViewById(R.id.dialog_custom_title)mTextViewContent = inflate.findViewById(R.id.dialog_custom_content)inflate.findViewById<View>(R.id.dialog_custom_yes).setOnClickListener{mCallBack?.onYesClick(this)}inflate.findViewById<View>(R.id.dialog_custom_no).setOnClickListener{dismiss()}}interface ClickCallBack {fun onYesClick(dialog:CustomDialog)}
}
布局文件:dialog_custom
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@drawable/white_circle_background10"android:orientation="vertical"><TextViewandroid:id="@+id/dialog_custom_title"android:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center"android:padding="20dp"android:textColor="@color/TextBlack"android:textSize="@dimen/TextSizeTitle" /><TextViewandroid:id="@+id/dialog_custom_content"android:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center"android:paddingBottom="20dp"android:textColor="@color/TextGray"android:textSize="@dimen/TextSizeContent" /><TextViewandroid:layout_width="match_parent"android:layout_height="1dp"android:background="@color/LightGrayStill" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:id="@+id/dialog_custom_no"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:gravity="center"android:padding="10dp"android:text="取消"android:textColor="@color/TextGray"android:textSize="@dimen/TextSizeContent" /><TextViewandroid:layout_width="1dp"android:layout_height="match_parent"android:background="@color/LightGrayStill" /><TextViewandroid:id="@+id/dialog_custom_yes"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="1"android:gravity="center"android:padding="10dp"android:text="确认"android:textColor="@color/TextGray"android:textSize="@dimen/TextSizeContent" /></LinearLayout></LinearLayout>
Android 简易的自定义确认弹框AlertDialog相关推荐
- Android自定义Dialog弹框效果
这是弹框输入密码的,这里还有一个是我发现一个博友写的自定义Dialog弹框信息和背景阴影显示 ,两者结合一起看,最好了!!! 下面是弹框输入密码的!!! 首先需要自定义一个类,继承Dialog pac ...
- vue 组件封装 确认弹框带可以自定义titile ,内容,和取消,确定按钮的弹窗 slot插槽
一,子组件 modalConfirm.vue 文件封装 <template><div class="confirmBgc animations" :style=& ...
- Android常见的三种弹框
Android在开发中经常会遇到有弹框的需求.经常使用的有Dialog 弹框,Window弹框,Activity伪弹框这三种. 感谢http://sigechuizi.cn/article/107 A ...
- 微信小程序自定义授权弹框
微信小程序自定义授权弹框 最近微信获取用户信息的接口有调整,就是这货:wx.getUserInfo(OBJECT),文档描述如下: 此接口有调整,使用该接口将不再出现授权弹窗,请使用 <butt ...
- android筛选功能代码,Android中 TeaScreenPopupWindow多类型筛选弹框功能的实例代码
Github地址 YangsBryant/TeaScreenPopupWindow (Github排版比较好,建议进入这里查看详情,如果觉得好,点个star吧!) 引入module allprojec ...
- Modal的二次确认弹框触发时机
Modal的二次确认弹框触发时机 react中modal中的值变化了之后点击取消弹出二次确认弹窗,要是值没有变化可以直接关闭modal. 在项目里边有个需求,就是需要我们的modal弹窗(modal里 ...
- elementUI table自定义表头弹框搜索,排序,显示tag标签
elementUI table自定义表头弹框搜索,排序,显示tag标签 允许一种排序,多种搜索条件 包括三种类别,添加了solt插槽,也可以自定义: 输入框[input] 多选[checkbox] 范 ...
- 如何实现接口统一入口_网易考拉Android App如何实现统一弹框
摘要 在快速开发的背景下,经历了n个版本后的考拉Android App中已经存在了各种各样看似相同却各有差别的弹框样式.其中包括系统弹框和自定义弹框,并且在线上时常会出现IllegalArgument ...
- android 弹出框带标题栏,Android开发靠标题栏的弹框
一.效果图 title_dialog.png 二.思路 首先它是一个弹框,只是弹框的布局做些处理,布局占满屏幕,只有需要白色的布局的背景设为白色.其他没设置背景颜色,自然用dialog的style的w ...
最新文章
- MySQL中有哪些锁?
- 洛谷 1858 多人背包
- 监听router_深入揭秘前端路由本质,手写 mini-router
- “别了,小黄文” 微信打击低俗小说:2019年处理违规账号6.6万+
- 解决springmvc在multipart/form-data方式提交请求在过滤器Filter中获取不到参数的问题
- ReactNative 启动js server报错:Metro Bundler can't listen on port 8081
- 基于MATLAB的数字图像处理-图像进行灰度化
- Python爆破ZIP文件(支持纯数字数字+字母密码本)
- 群发邮件软件和邮件群发工具哪个好?如何群发邮件不进入垃圾箱
- android对话框activity,Android使用Activity用作弹出式对话框
- 论文阅读:Improved Denoising Diffusion Probabilistic Models
- 关于 YCbCr(YUV) 格式视频流的介绍
- 关镇铨,有人为其洗白,我只想说我的亲身经历,最后悔的就是选择他们
- Livy 安装使用说明
- java 影院售票系统_java电影院售票系统
- 会所会员消费管理系统解决方案
- 如何选择电路中的电容
- 第5章 Linux上管理文件系统
- 软件设计师上午题简易整理
- 单片机产生锯齿波c语言,单片机产生方波、锯齿波、三角波程序