我想在 Kotlin 中创建一个自定义对话框
.我在 Stack Overflow 上查看了有关此主题的问题,但找不到任何有用的信息.我该怎么做?
I want to create a custom dialog
in Kotlin. I looked through questions on this theme on Stack Overflow, but I could not find any useful information. How can I do it?
您可以将以下代码用于自定义对话框.这是我的工作代码.
You can use below code for a custom Dialog. It's my working code.
private fun showDialog(title: String) {
val dialog = Dialog(activity)
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
dialog.setCancelable(false)
dialog.setContentView(R.layout.custom_layout)
val body = dialog.findViewById(R.id.body) as TextView
body.text = title
val yesBtn = dialog.findViewById(R.id.yesBtn) as Button
val noBtn = dialog.findViewById(R.id.noBtn) as TextView
yesBtn.setOnClickListener {
dialog.dismiss()
}
noBtn.setOnClickListener { dialog.dismiss() }
dialog.show()
}
这篇关于Kotlin - Android 中的自定义对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!