Android 自定义对话框工具之空祖Dialog,集成三种风格+夜间模式对话框,以及等待、提示、分享等特色对话框,支持花式自定义
一.Dialog1:(创建对应的自定义类和对应的布局或者共用一个自定义类根据传进来的type来判断对应的布局和控件显示隐藏等)
1.自定义dialog类:
import android.app.Dialog
import android.content.Context
import android.text.TextUtils
import android.view.View
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import com.duoge.weeboos.siji.R
/**
*语音验证码提示框
*/
class CommonDialog3 : Dialog {
// var ImageView ivDialogCancel? = null;
var tvTitle: TextView? = null
var ivDialogIcon: ImageView? = null
var tvDialogContent: TextView? = null
var btDialogConfirm: TextView? = null //确定按钮可通过外部自定义按钮内容
var tvDialogCancel: TextView? = null //取消
constructor(context: Context) : super(context) {
initView()
}
constructor(context: Context, themeStyle: Int) : super(context, themeStyle) {
initView()
}
private fun initView() {
setContentView(R.layout.dialog_voice_verification_code)
setCanceledOnTouchOutside(false)
tvTitle = findViewById(R.id.tv_title)
// tvDialogContent = findViewById(R.id.tv_dialog_content)
btDialogConfirm = findViewById(R.id.tv_ok)
tvDialogCancel = findViewById(R.id.tv_cancel)
}
class Builder(val context: Context) {
var confirmListener: OnConfirmListener? = null
var cancelListener: OnCancelListener? = null
var title: String? = null
var icon: Int? = 0
var content: String? = null
var btConfirmText: String? = null
var tvCancelText: String? = null
var cancelIsVisibility: Boolean? = true
fun setOnConfirmListener(confirmListener: OnConfirmListener): Builder {
this.confirmListener = confirmListener
return this
}
fun setOnCancelListener(cancelListener: OnCancelListener): Builder {
this.cancelListener = cancelListener
return this
}
fun setTitle(title: String): Builder {
this.title = title
return this
}
fun setIcon(icon: Int): Builder {
this.icon = icon
return this
}
fun setContent(content: String): Builder {
this.content = content
return this
}
// 点击确定按钮的文字
fun setConfirmText(btConfirmText: String): Builder {
this.btConfirmText = btConfirmText
return this
}
//取消按钮的文字
fun setCancelText(tvCancelText: String): Builder {
this.tvCancelText = tvCancelText
return this
}
fun setCancelIconIsVisibility(cancelIsVisibility: Boolean): Builder {
this.cancelIsVisibility = cancelIsVisibility
return this
}
fun create(): CommonDialog3 {
val dialog = CommonDialog3(context, R.style.custom_dialog2)
if (!TextUtils.isEmpty(title)) {
dialog.tvTitle?.text = "请注意接听语音来电免费获取验证码"
} else {
dialog.tvTitle?.text = "请注意接听语音来电免费获取验证码"//this.title
// dialog.tvTitle?.visibility = View.GONE
}
// dialog.tvDialogContent?.text = this.content
// if (icon != 0) {
//// dialog.ivDialogIcon?.setImageResource(this.icon!!)
// }
dialog.btDialogConfirm?.text = this.btConfirmText ?: "确认接听"
if (this.cancelIsVisibility!!) {
dialog.tvDialogCancel?.text = this.tvCancelText ?: "取消"
} else {
// dialog.tvDialogCancel?.visibility = View.GONE
}
if (cancelListener != null) {
dialog.tvDialogCancel?.setOnClickListener { v -> cancelListener!!.onClick(dialog) }
}
if (confirmListener != null) {
dialog.btDialogConfirm?.setOnClickListener { v -> confirmListener!!.onClick(dialog) }
}
return dialog
}
}
// 点击弹窗取消按钮回调
interface OnCancelListener {
fun onClick(dialog: Dialog)
}
// 点击弹窗跳转回调
interface OnConfirmListener {
fun onClick(dialog: Dialog)
}
}
2.布局:
3.调用Dialog:
//弹框式样
CommonDialog3.Builder(this)
.setTitle("请注意接听语音来电免费获取验证码")
.setConfirmText("确认接听")
// .setContent("请注意接听语音来电免费获取验证码")
.setCancelText("取消")
.setOnConfirmListener(object : CommonDialog3.OnConfirmListener {
override fun onClick(dialog: Dialog) {
loginViewModel.getPhoneVeryCode(
RegisterViewModel.VERY_VCODE,
edt_phone_email.text.toString(),
1
)
dialog.dismiss()
mDisposable?.dispose()
tv_get_very_code.isEnabled = false
tv_get_very_isvoice.isEnabled = false
isvoice.visibility = View.GONE
tv_get_very_code.text = "(60s)重发"
//倒计时
mDisposable = mObserver?.subscribeOn(Schedulers.newThread())?.observeOn(
AndroidSchedulers.mainThread()
)
?.subscribe { time ->
changeUi(time)
}
}
})
.setOnCancelListener(object : CommonDialog3.OnCancelListener {
override fun onClick(dialog: Dialog) {
dialog.dismiss()
}
})
.create()
.show()
private fun changeUi(time: Long) {
if (time < 60) {
tv_get_very_code.text = "(${60 - time}s)重发"
} else {
mDisposable?.dispose()
// isvoice.visibility = View.VISIBLE
tv_get_very_code.isEnabled = true
tv_get_very_code.text = "获取验证码"
if (NumberUtils.isPhone(edt_phone_email.text.toString())) {
tv_get_very_isvoice.isEnabled = true
isvoice.visibility = View.VISIBLE
}
}
}
4.属性配置:
5.其它式样的Dialog:(与上述Dialog如出一辙,只作为案例参考)
import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.text.*
import android.text.style.ForegroundColorSpan
import android.util.Log
import android.view.Gravity
import android.view.KeyEvent
import android.view.View
import android.widget.*
import com.duoge.weeboos.siji.R
import android.view.WindowManager
import com.duoge.weeboos.siji.event.BuyDialogEvent
import com.duoge.weeboos.siji.utils.DialogType
import com.duoge.weeboos.siji.utils.PayMethodUtils
import com.jiuwe.common.util.PreferenceUtils
import kotlinx.android.synthetic.main.dialog_ordinary_buy.*
import kotlinx.android.synthetic.main.dialog_safecenter.*
import org.greenrobot.eventbus.EventBus
import java.math.BigDecimal
/**
* 普通买入弹框
*/
class OrdinaryBuyDialog : Dialog {
var ckb_wechat: CheckBox? = null
var ckb_alipay: CheckBox? = null
var ckb_bank: CheckBox? = null
var tv_limit: TextView? = null
var safe_sumbit: TextView? = null
var tv_real_payment: TextView? = null
var tv_buynumber: TextView? = null
var rl_blank_page: RelativeLayout? = null
var et_purchase_amount: EditText? = null
//
var tv_unit_price: TextView? = null
constructor(context: Context) : super(context) {
initView()
}
constructor(context: Context, themeStyle: Int) : super(context, themeStyle) {
initView()
}
private fun initView() {
setContentView(R.layout.dialog_ordinary_buy)
setCanceledOnTouchOutside(false)
et_purchase_amount = findViewById(R.id.et_purchase_amount)
tv_limit = findViewById(R.id.tv_limit)
tv_real_payment = findViewById(R.id.tv_real_payment)
ckb_bank = findViewById(R.id.ckb_bank)
ckb_alipay = findViewById(R.id.ckb_alipay)
ckb_wechat = findViewById(R.id.ckb_wechat)
safe_sumbit = findViewById(R.id.safe_sumbit)
tv_buynumber = findViewById(R.id.tv_buynumber)
rl_blank_page = findViewById(R.id.rl_blank_page)
tv_unit_price = findViewById(R.id.tv_unit_price)
}
class Builder(val context: Context) {
var confirmListener: OnConfirmListener? = null
var allListener: OnAllListener? = null
var cancelListener: OnCancelListener? = null
var title: String? = null
var icon: Int? = 0
var availableBalanceType: Int? = 0
var content: String? = null
var btConfirmText: String? = null
var tvCancelText: String? = null
var cancelIsVisibility: Boolean? = true
var phonetext: String? = null
var unitPrice: String? = null
var limit: String? = null
var availableBalance: String? = null
var buyOrSell: Int? = null
var payTyp: Int? = null
var emailtext: String? = null
var ga: String? = null
var tvphonecodeListener: OnPhoneCodeListener? = null
var type: Int? = 0
// var tvisvoiceListener: OnTvIsvoiceListener? = null
fun setOnPhoneCodeListener(tvphonecodeListener: OnPhoneCodeListener): Builder {
this.tvphonecodeListener = tvphonecodeListener
return this
}
// fun setOnTvIsvoice(tvisvoiceListener: OnTvIsvoiceListener): Builder {
// this.tvisvoiceListener = tvisvoiceListener
// return this
// }
fun setOnConfirmListener(confirmListener: OnConfirmListener): Builder {
this.confirmListener = confirmListener
return this
}
fun setOnAllmListener(allListener: OnAllListener): Builder {
this.allListener = allListener
return this
}
fun setOnCancelListener(cancelListener: OnCancelListener): Builder {
this.cancelListener = cancelListener
return this
}
fun setTitle(title: String): Builder {
this.title = title
return this
}
//获取调用弹窗页面
fun setType(type: Int): Builder {
this.type = type
return this
}
fun setIcon(icon: Int): Builder {
this.icon = icon
return this
}
fun setContent(content: String): Builder {
this.content = content
return this
}
// 点击确定按钮的文字
fun setConfirmText(btConfirmText: String): Builder {
this.btConfirmText = btConfirmText
return this
}
//传入用户输入的手机号
fun setPhonetext(phone: String): Builder {
this.phonetext = phone
return this
}
//传入支付方式
fun setPayType(payTyp: Int): Builder {
this.payTyp = payTyp
return this
}
//传入单价
fun setUnitPrice(unitPrice: String): Builder {
this.unitPrice = unitPrice
return this
}
//传入限额
fun setLimit(limit: String): Builder {
this.limit = limit
return this
}
//传入可用余额
fun setAvailableBalance(availableBalance: String,availableBalanceType:Int): Builder {
this.availableBalance = availableBalance
this.availableBalanceType = availableBalanceType
return this
}
//传入买入卖出类型
fun setBuyOrSell(buyOrSell: Int): Builder {
this.buyOrSell = buyOrSell
return this
}
//传入用户输入的注册邮箱号
fun setEmailtext(email: String): Builder {
this.emailtext = email
return this
}
//传入用户是否开启谷歌验证码标志位
fun setGatext(ge: String): Builder {
this.ga = ge
return this
}
//取消按钮的文字
fun setCancelText(tvCancelText: String): Builder {
this.tvCancelText = tvCancelText
return this
}
fun setCancelIconIsVisibility(cancelIsVisibility: Boolean): Builder {
this.cancelIsVisibility = cancelIsVisibility
return this
}
fun create(): OrdinaryBuyDialog {
val dialog = OrdinaryBuyDialog(context, R.style.custom_dialog2)
dialog.setCancelable(true)
// var s1 = SpannableString("收不到短信验证码?获取语音验证码")
// s1.setSpan(
// ForegroundColorSpan(Color.parseColor("#ff1774dd")),
// 11,
// 16,
// Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
// )
dialog.setOnKeyListener { dialog, keyCode, event ->
if (keyCode == KeyEvent.KEYCODE_BACK && event.repeatCount == 0) {
//dialog点击返回按钮时通知改变变量的值
EventBus.getDefault().post(BuyDialogEvent())
// dialog.dismiss();
}
false
}
// dialog.tv_get_very_bindcard_isvoice?.text = s1
dialog.window.setGravity(Gravity.BOTTOM)
//设置dialog动画
dialog.window.setWindowAnimations(R.style.dialogWindowAnim)
//获得window窗口的属性
val lp = dialog.window.attributes
//设置窗口宽度为充满全屏
dialog.dialog_phone?.text = phonetext
lp.width = WindowManager.LayoutParams.MATCH_PARENT
// dialog.ll_blank_page?.setOnClickListener {
// EventBus.getDefault().post(BuyDialogEvent())
// dialog.dismiss();
// }
//设置选择状态
dialog.ckb_bank?.setOnCheckedChangeListener { buttonView, isChecked ->
if (isChecked) {
dialog.ckb_bank?.setTextColor(context.resources.getColor(R.color.blue_tv_bg))
}else{
dialog.ckb_bank?.setTextColor(context.resources.getColor(R.color.account))
}
}
dialog.ckb_wechat?.setOnCheckedChangeListener { buttonView, isChecked ->
if (isChecked) {
dialog.ckb_wechat?.setTextColor(context.resources.getColor(R.color.blue_tv_bg))
}else{
dialog.ckb_wechat?.setTextColor(context.resources.getColor(R.color.account))
}
}
dialog.ckb_alipay?.setOnCheckedChangeListener { buttonView, isChecked ->
if (isChecked) {
dialog.ckb_alipay?.setTextColor(context.resources.getColor(R.color.blue_tv_bg))
}else{
dialog.ckb_alipay?.setTextColor(context.resources.getColor(R.color.account))
}
}
dialog.tv_unit_price?.text = this.unitPrice
dialog.tv_limit?.text = this.limit
if(availableBalanceType == 2 || availableBalanceType == 4){//卖出
dialog.tv_available_balance?.visibility =View.VISIBLE
}else{
dialog.tv_available_balance?.visibility =View.GONE
}
dialog.tv_available_balance?.text = this.availableBalance
if(buyOrSell == 0){
dialog.tv_buynumber?.setText("买入量")
dialog.et_purchase_amount?.setHint("请输入买入量")
}else if(buyOrSell == 1){
dialog.tv_buynumber?.setText("卖出量")
dialog.et_purchase_amount?.setHint("请输入卖出量")
}
// 自己的绑定支付方式和可用的支付方式对配对,不可用的将置为不可点击,,这块逻辑有待优化
var bound = 0
if (PreferenceUtils.getBOUND() == "1" && (payTyp == 1 || payTyp == 3 || payTyp == 7 || payTyp == 5)) {
bound = 1
} else if (PreferenceUtils.getBOUND() == "2" && (payTyp == 2 || payTyp == 3 || payTyp == 7 || payTyp == 6)) {
bound = 2
} else if (PreferenceUtils.getBOUND() == "4" && (payTyp == 4 || payTyp == 5 || payTyp == 7 || payTyp == 6)) {
bound = 4
} else if (PreferenceUtils.getBOUND() == "3" && (payTyp == 3 || payTyp == 7)) {
bound = 3
} else if (payTyp == 1 && (PreferenceUtils.getBOUND() == "1" || PreferenceUtils.getBOUND() == "3" || PreferenceUtils.getBOUND() == "5" || PreferenceUtils.getBOUND() == "7")) {
bound = 1
} else if (payTyp == 2 && (PreferenceUtils.getBOUND() == "2" || PreferenceUtils.getBOUND() == "4" || PreferenceUtils.getBOUND() == "6" || PreferenceUtils.getBOUND() == "7")) {
bound = 2
} else if (payTyp == 4 && (PreferenceUtils.getBOUND() == "4" || PreferenceUtils.getBOUND() == "6" || PreferenceUtils.getBOUND() == "5" || PreferenceUtils.getBOUND() == "7")) {
bound = 4
} else if (payTyp == 3 && (PreferenceUtils.getBOUND() == "3" || PreferenceUtils.getBOUND() == "7")) {
bound = 3
} else if (payTyp == 5 && (PreferenceUtils.getBOUND() == "5" || PreferenceUtils.getBOUND() == "7")) {
bound = 5
} else if (PreferenceUtils.getBOUND() == "5" && (payTyp == 5 || payTyp == 7)) {
bound = 5
} else if (PreferenceUtils.getBOUND() == "6" && (payTyp == 6 || payTyp == 7)) {
bound = 6
} else if (payTyp == 6 && (PreferenceUtils.getBOUND() == "6" || PreferenceUtils.getBOUND() == "7")) {
bound = 6
} else if (payTyp.toString() == PreferenceUtils.getBOUND()) {
bound = payTyp!!.toInt()
}
PayMethodUtils.setVisibility(context,bound, dialog.ckb_bank, dialog.ckb_alipay, dialog.ckb_wechat)
dialog.et_purchase_amount?.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable?) {
if (s.toString().isEmpty() || s.toString().toDouble() == 0.0) {
// tv_order_price.text = ""
} else {
val bigDecimal =
BigDecimal(s.toString()).multiply(BigDecimal(unitPrice))
.setScale(2, BigDecimal.ROUND_HALF_UP)
dialog.tv_real_payment?.text = bigDecimal.toPlainString()
}
}
override fun beforeTextChanged(
s: CharSequence?,
start: Int,
count: Int,
after: Int
) {
}
override fun onTextChanged(
s: CharSequence?,
start: Int,
before: Int,
count: Int
) {
}
})
dialog.ckb_bank?.setOnClickListener {
}
// if (!TextUtils.isEmpty(title)) {
// dialog.tvTitle?.text = this.title
// } else {
// dialog.tvTitle?.visibility = View.GONE
// }
// if (ga == "1") {
// dialog.gaview?.visibility = View.VISIBLE
// } else {
// dialog.gaview?.visibility = View.GONE
// }
when (type) {
// DialogType.BIND_CARD -> {
// dialog.email_view?.visibility = View.GONE
// }
// DialogType.SAFE_PHONE_NEW -> {
// dialog.email_view?.visibility = View.GONE
// dialog.zijin_view?.visibility = View.GONE
// dialog.ga_view?.visibility = View.GONE
// }
}
// dialog.tvDialogContent?.text = this.content
// if (icon != 0) {
//// dialog.ivDialogIcon?.setImageResource(this.icon!!)
// }
dialog.safe_sumbit?.text = this.btConfirmText ?: "确认"
if (this.cancelIsVisibility!!) {
// dialog.tvDialogCancel?.text = this.tvCancelText ?: "取消"
} else {
// dialog.tvDialogCancel?.visibility = View.GONE
}
if (cancelListener != null) {
// dialog.tvDialogCancel?.setOnClickListener { v -> cancelListener!!.onClick(dialog) }
}
if (confirmListener != null) {
dialog.safe_sumbit?.setOnClickListener { v -> confirmListener!!.onClick(dialog) }
}
if (allListener != null) {
dialog.rl_blank_page?.setOnClickListener { v -> allListener!!.onClick(dialog) }
}
// if (tvphonecodeListener != null) {
// dialog.tvphonecode?.setOnClickListener { v -> tvphonecodeListener!!.onClick(dialog) }
// }
// if (tvisvoiceListener != null) {
// dialog.tv_get_very_bindcard_isvoice?.setOnClickListener { v ->
// tvisvoiceListener!!.onClick(
// dialog
// )
// }
// }
return dialog
}
}
// 点击弹窗取消按钮回调
interface OnCancelListener {
fun onClick(dialog: Dialog)
}
// 点击弹窗跳转回调
interface OnConfirmListener {
fun onClick(dialog: Dialog)
}
//空白处
interface OnAllListener {
fun onClick(dialog: Dialog)
}
//发送手机验证码
interface OnPhoneCodeListener {
fun onClick(dialog: Dialog)
}
//获取语音验证码
interface OnTvIsvoiceListener {
fun onClick(dialog: Dialog)
}
}
6.其它式样:
import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.text.SpannableString
import android.text.Spanned
import android.text.TextUtils
import android.text.style.ForegroundColorSpan
import android.view.Gravity
import android.view.View
import android.widget.*
import com.duoge.weeboos.siji.R
import android.view.WindowManager
import com.duoge.weeboos.siji.utils.DialogType
import kotlinx.android.synthetic.main.dialog_safecenter.*
/**
* 安全验证
*/
class SafeCenterDialog : Dialog {
// var ImageView ivDialogCancel? = null;
var tvTitle: TextView? = null
var ivDialogIcon: ImageView? = null
var tvDialogContent: TextView? = null
var btDialogConfirm: TextView? = null //确定按钮可通过外部自定义按钮内容
var tvDialogCancel: TextView? = null //取消
var tvphoneInput: EditText? = null//输入手机验证码
var tvphonecode: TextView? = null//发送手机验证码
var tvemailInput: EditText? = null////输入邮箱验证码
var tvemailcode: TextView? = null//发送邮箱验证码
var tvgaInput: TextView? = null//输入谷歌验证码
var tvsumbit: Button? = null//提交
var gaview: LinearLayout? = null//是否显示谷歌验证码输入框
var close_dialog: TextView? = null//关闭弹窗
var email_view: LinearLayout? = null
var zijin_view: LinearLayout? = null//是否显示资金密码
var ga_view: LinearLayout? = null//是否显示资金密码
var center_mima_code: EditText? = null//输入资金密码
var dialog_phone: TextView? = null
var bindcard_isvoice: RelativeLayout? = null
var tv_get_very_bindcard_isvoice: TextView? = null
constructor(context: Context) : super(context) {
initView()
}
constructor(context: Context, themeStyle: Int) : super(context, themeStyle) {
initView()
}
private fun initView() {
setContentView(R.layout.dialog_safecenter)
setCanceledOnTouchOutside(false)
tvTitle = findViewById(R.id.tv_dialog_title)
// tvDialogContent = findViewById(R.id.tv_dialog_content)
//bindcard_isvoice
//tv_get_very_bindcard_isvoice
bindcard_isvoice = findViewById(R.id.bindcard_isvoice)
tv_get_very_bindcard_isvoice = findViewById(R.id.tv_get_very_bindcard_isvoice)
btDialogConfirm = findViewById(R.id.safe_sumbit)
tvDialogCancel = findViewById(R.id.close_dialog)
tvphoneInput = findViewById(R.id.center_input_code)
tvphonecode = findViewById(R.id.phone_code)
tvemailInput = findViewById(R.id.center_email_code)
tvemailcode = findViewById(R.id.email_code)
tvgaInput = findViewById(R.id.center_ga_code)
tvsumbit = findViewById(R.id.safe_sumbit)
gaview = findViewById(R.id.ga_view)
dialog_phone = findViewById(R.id.dialog_phone)
email_view = findViewById(R.id.email_view)
center_mima_code = findViewById(R.id.center_mima_code)
zijin_view = findViewById(R.id.zijin_view)
ga_view = findViewById(R.id.ga_view)
}
class Builder(val context: Context) {
var confirmListener: OnConfirmListener? = null
var cancelListener: OnCancelListener? = null
var title: String? = null
var icon: Int? = 0
var content: String? = null
var btConfirmText: String? = null
var tvCancelText: String? = null
var cancelIsVisibility: Boolean? = true
var phonetext: String? = null
var emailtext: String? = null
var ga: String? = null
var tvphonecodeListener: OnPhoneCodeListener? = null
var type: Int? = 0
var tvisvoiceListener: OnTvIsvoiceListener? = null
fun setOnPhoneCodeListener(tvphonecodeListener: OnPhoneCodeListener): Builder {
this.tvphonecodeListener = tvphonecodeListener
return this
}
fun setOnTvIsvoice(tvisvoiceListener: OnTvIsvoiceListener): Builder {
this.tvisvoiceListener = tvisvoiceListener
return this
}
fun setOnConfirmListener(confirmListener: OnConfirmListener): Builder {
this.confirmListener = confirmListener
return this
}
fun setOnCancelListener(cancelListener: OnCancelListener): Builder {
this.cancelListener = cancelListener
return this
}
fun setTitle(title: String): Builder {
this.title = title
return this
}
//获取调用弹窗页面
fun setType(type: Int): Builder {
this.type = type
return this
}
fun setIcon(icon: Int): Builder {
this.icon = icon
return this
}
fun setContent(content: String): Builder {
this.content = content
return this
}
// 点击确定按钮的文字
fun setConfirmText(btConfirmText: String): Builder {
this.btConfirmText = btConfirmText
return this
}
//传入用户输入的手机号
fun setPhonetext(phone: String): Builder {
this.phonetext = phone
return this
}
//传入用户输入的注册邮箱号
fun setEmailtext(email: String): Builder {
this.emailtext = email
return this
}
//传入用户是否开启谷歌验证码标志位
fun setGatext(ge: String): Builder {
this.ga = ge
return this
}
//取消按钮的文字
fun setCancelText(tvCancelText: String): Builder {
this.tvCancelText = tvCancelText
return this
}
fun setCancelIconIsVisibility(cancelIsVisibility: Boolean): Builder {
this.cancelIsVisibility = cancelIsVisibility
return this
}
fun create(): SafeCenterDialog {
val dialog = SafeCenterDialog(context, R.style.custom_dialog2)
// var s1 = SpannableString("收不到短信验证码?获取语音验证码")
// s1.setSpan(
// ForegroundColorSpan(Color.parseColor("#ff1774dd")),
// 11,
// 16,
// Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
// )
// dialog.tv_get_very_bindcard_isvoice?.text = s1
dialog.window.setGravity(Gravity.BOTTOM)
//获得window窗口的属性
val lp = dialog.window.attributes
//设置窗口宽度为充满全屏
dialog.dialog_phone?.text = phonetext
lp.width = WindowManager.LayoutParams.MATCH_PARENT
if (!TextUtils.isEmpty(title)) {
dialog.tvTitle?.text = this.title
} else {
dialog.tvTitle?.visibility = View.GONE
}
if (ga == "1") {
dialog.gaview?.visibility = View.VISIBLE
} else {
dialog.gaview?.visibility = View.GONE
}
when (type) {
DialogType.BIND_CARD -> {
dialog.email_view?.visibility = View.GONE
}
DialogType.SAFE_PHONE_NEW -> {
dialog.email_view?.visibility = View.GONE
dialog.zijin_view?.visibility = View.GONE
dialog.ga_view?.visibility = View.GONE
}
}
dialog.tvDialogContent?.text = this.content
if (icon != 0) {
// dialog.ivDialogIcon?.setImageResource(this.icon!!)
}
dialog.btDialogConfirm?.text = this.btConfirmText ?: "确认"
if (this.cancelIsVisibility!!) {
dialog.tvDialogCancel?.text = this.tvCancelText ?: "取消"
} else {
dialog.tvDialogCancel?.visibility = View.GONE
}
if (cancelListener != null) {
dialog.tvDialogCancel?.setOnClickListener { v -> cancelListener!!.onClick(dialog) }
}
if (confirmListener != null) {
dialog.btDialogConfirm?.setOnClickListener { v -> confirmListener!!.onClick(dialog) }
}
if (tvphonecodeListener != null) {
dialog.tvphonecode?.setOnClickListener { v -> tvphonecodeListener!!.onClick(dialog) }
}
if (tvisvoiceListener != null) {
dialog.tv_get_very_bindcard_isvoice?.setOnClickListener { v ->
tvisvoiceListener!!.onClick(
dialog
)
}
}
return dialog
}
}
// 点击弹窗取消按钮回调
interface OnCancelListener {
fun onClick(dialog: Dialog)
}
// 点击弹窗跳转回调
interface OnConfirmListener {
fun onClick(dialog: Dialog)
}
//发送手机验证码
interface OnPhoneCodeListener {
fun onClick(dialog: Dialog)
}
//获取语音验证码
interface OnTvIsvoiceListener {
fun onClick(dialog: Dialog)
}
}
EditText配置:
分割线配置:
二.Dialog2:(只需要创建自己需要的布局即可,全部使用同一个自定义类)
1.添加依赖:
implementation 'com.kongzue.dialog_v3:dialog:3.1.0'
2.自定义类:
val dialog = CustomDialog.build(this, R.layout.dialog_google_code, object : CustomDialog.OnBindView {
override fun onBind(dialog: CustomDialog?, v: View?) {
val tv_cancel = v?.findViewById(R.id.close_dialog)
val tv_ok = v?.findViewById(R.id.safe_sumbit)
val edtPassword = v?.findViewById(R.id.et_google_code)
tv_cancel?.setOnClickListener {
dialog?.doDismiss()
}
tv_ok?.setOnClickListener {
if (TextUtils.isEmpty(edtPassword?.text?.toString())) {
ToastUtil.showShort("请输入谷歌验证码")
return@setOnClickListener
}
mViewModel.login(
edt_password.text.toString(),
edt_very_code.text.toString(),
email,
phone,
edtPassword?.text?.toString(),
edt_very_code2.text.toString()
)
}
}
}).setFullScreen(true)
dialog.show()
3.布局: