直播系统源码,简易的自定义确认弹框AlertDialog
直播系统源码,简易的自定义确认弹框AlertDialog实现的相关代码
1 | <br> CustomDialog( this , "清空输入" , "确定要清空已输入内容吗?" , object : CustomDialog.ClickCallBack {<br> override fun onYesClick(dialog: CustomDialog) {<br> //点击确认按钮后具体操作<br> dialog.dismiss()<br> }<br> <br> }).show() |
自定义Dialog代码:
1 | <br> /**<br> * Created by Xinghai.Zhao<br> * 自定义选择弹框<br> */ <br> @SuppressLint ( "InflateParams" )<br> class CustomDialog(context: Context?) : AlertDialog(context){<br> var mCallBack: ClickCallBack? = null <br> var mTextViewTitle: TextView? = null <br> var mTextViewContent: TextView? = null <br> constructor(context: Context?, title: String?, content: String?, callBack: ClickCallBack) : this (context) {<br> mCallBack = callBack<br> if (title != null ) mTextViewTitle?.text = title<br> if (content != null ) mTextViewContent?.text = content<br> }<br> init {<br> val inflate = LayoutInflater.from(context).inflate(R.layout.dialog_custom, null )<br> setView(inflate)<br> //设置点击别的区域不关闭页面<br> setCancelable(false)<br> mTextViewTitle = inflate.findViewById(R.id.dialog_custom_title)<br> mTextViewContent = inflate.findViewById(R.id.dialog_custom_content)<br> inflate.findViewById<View>(R.id.dialog_custom_yes).setOnClickListener{mCallBack?.onYesClick(this)}<br> inflate.findViewById<View>(R.id.dialog_custom_no).setOnClickListener{dismiss()}<br> }<br> interface ClickCallBack {<br> fun onYesClick(dialog:CustomDialog)<br> }<br>} |
布局文件:dialog_custom
1 | <br><?xml version= "1.0" encoding= "utf-8" ?><br><LinearLayout xmlns:android= "http://schemas.android.com/apk/res/android" <br> android:layout_width= "match_parent" <br> android:layout_height= "wrap_content" <br> android:background= "@drawable/white_circle_background10" <br> android:orientation= "vertical" ><br> <br> <TextView<br> android:id= "@+id/dialog_custom_title" <br> android:layout_width= "match_parent" <br> android:layout_height= "wrap_content" <br> android:gravity= "center" <br> android:padding= "20dp" <br> android:textColor= "@color/TextBlack" <br> android:textSize= "@dimen/TextSizeTitle" /><br> <br> <TextView<br> android:id= "@+id/dialog_custom_content" <br> android:layout_width= "match_parent" <br> android:layout_height= "wrap_content" <br> android:gravity= "center" <br> android:paddingBottom= "20dp" <br> android:textColor= "@color/TextGray" <br> android:textSize= "@dimen/TextSizeContent" /><br> <br> <TextView<br> android:layout_width= "match_parent" <br> android:layout_height= "1dp" <br> android:background= "@color/LightGrayStill" /><br> <br> <LinearLayout<br> android:layout_width= "match_parent" <br> android:layout_height= "wrap_content" <br> android:orientation= "horizontal" ><br> <br> <TextView<br> android:id= "@+id/dialog_custom_no" <br> android:layout_width= "0dp" <br> android:layout_height= "wrap_content" <br> android:layout_weight= "1" <br> android:gravity= "center" <br> android:padding= "10dp" <br> android:text= "取消" <br> android:textColor= "@color/TextGray" <br> android:textSize= "@dimen/TextSizeContent" /><br> <br> <TextView<br> android:layout_width= "1dp" <br> android:layout_height= "match_parent" <br> android:background= "@color/LightGrayStill" /><br> <br> <TextView<br> android:id= "@+id/dialog_custom_yes" <br> android:layout_width= "0dp" <br> android:layout_height= "wrap_content" <br> android:layout_weight= "1" <br> android:gravity= "center" <br> android:padding= "10dp" <br> android:text= "确认" <br> android:textColor= "@color/TextGray" <br> android:textSize= "@dimen/TextSizeContent" /><br> <br> <br> </LinearLayout><br> <br></LinearLayout> |
以上就是直播系统源码,简易的自定义确认弹框AlertDialog实现的相关代码, 更多内容欢迎关注之后的文章
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现