短视频程序开发,简易的自定义确认弹框AlertDialog

短视频程序开发,简易的自定义确认弹框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? = null
    var mTextViewTitle: TextView? = null
    var mTextViewContent: TextView? = null
    constructor(context: Context?, title: String?, content: String?, callBack: ClickCallBack) : this(context) {
        mCallBack = callBack
        if (title != null) mTextViewTitle?.text = title
        if (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">
 
    <TextView
        android: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" />
 
    <TextView
        android: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" />
 
    <TextView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/LightGrayStill" />
 
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
 
        <TextView
            android: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" />
 
        <TextView
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="@color/LightGrayStill" />
 
        <TextView
            android: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>

 

以上就是 短视频程序开发,简易的自定义确认弹框AlertDialog实现的相关代码,更多内容欢迎关注之后的文章

 

posted @   云豹科技-苏凌霄  阅读(45)  评论(0编辑  收藏  举报
编辑推荐:
· 对象命名为何需要避免'-er'和'-or'后缀
· SQL Server如何跟踪自动统计信息更新?
· AI与.NET技术实操系列:使用Catalyst进行自然语言处理
· 分享一个我遇到过的“量子力学”级别的BUG。
· Linux系列:如何调试 malloc 的底层源码
阅读排行:
· 对象命名为何需要避免'-er'和'-or'后缀
· JDK 24 发布,新特性解读!
· C# 中比较实用的关键字,基础高频面试题!
· .NET 10 Preview 2 增强了 Blazor 和.NET MAUI
· SQL Server如何跟踪自动统计信息更新?
点击右上角即可分享
微信分享提示