本文介紹了Kotlin - Android 中的自定義對話框的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我想在 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模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!