第九章:kotlin:自定义dialog
kotlin学习笔记
·
kotlin学习笔记
class DialogSucceed(context: Context) : AlertDialog(context),
View.OnClickListener {
constructor(context: Context?, line: Int?) : this(context!!) {
tv_grid_num.text = (line.toString() + "-")
}
init {
var layout = LayoutInflater.from(context).inflate(R.layout.dialog_pay_succeed, null)
setView(layout)
//设置点击别的区域关闭页面
setCancelable(true)
layout.ll_return.setOnClickListener(this)
layout.tv_go_home.setOnClickListener(this)
}
override fun show() {
val params: WindowManager.LayoutParams = window!!.attributes
params.width = 700
params.gravity = Gravity.CENTER
window!!.attributes = params
window!!.setBackgroundDrawableResource(android.R.color.transparent)
super.show()
}
override fun onClick(v: View?) {
when (v) {
ll_return -> dismiss()
tv_go_home -> dismiss()
}
}
}
调用方法
val dialog1 = DialogShopSucceed(mContext,1) dialog1.show()
更多推荐



所有评论(0)