Kotlin-Android中的自定义对话框 [英] Kotlin - custom dialog in Android

查看:1114
本文介绍了Kotlin-Android中的自定义对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Kotlin中创建自己的对话框.我在Stack Overflow上浏览了有关此主题的问题,但找不到任何有用的信息.我该怎么办?

I want to create my own 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 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.cutsom_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中的自定义对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆