如何在 kotlin 中使用自定义对话框
How to use a custom Dialog in kotlin
我有一个小 class,我想用它来显示和关闭我的对话框,我的改造响应正在加载项目列表
class ShowProgress(context: Context) : Dialog(context) {
var dialog = Dialog(context)
fun showDialog() {
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
dialog.setCancelable(false)
dialog.setContentView(R.layout.progress_layout)
dialog.show()
}
fun closeDialog() {
dialog.dismiss()
}
}
我正在显示对话框,但在响应完成时它不会关闭 ()。这到底是什么问题?
这是显示和关闭自定义弹出窗口的方法;
class ShowProgress(context: Context) : Dialog(context) {
init {
dialog = Dialog(context)
}
fun showPopup() {
val dialogview = LayoutInflater.from(context)
.inflate(R.layout.dialog_choose_image, null, false)
//initializing dialog screen
dialog?.setCancelable(true)
dialog?.setContentView(dialogview)
dialog?.show()
}
companion object{
var dialog: Dialog? = null
fun dismissPopup() = dialog?.let { dialog!!.dismiss() }
}
}
并且从视图中您可以像这样访问它。
val showProgress = ShowProgress(this) showProgress.showPopup()
并在您想关闭弹出窗口时关闭它
ShowProgress.dismissPopup()
我有一个小 class,我想用它来显示和关闭我的对话框,我的改造响应正在加载项目列表
class ShowProgress(context: Context) : Dialog(context) {
var dialog = Dialog(context)
fun showDialog() {
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
dialog.setCancelable(false)
dialog.setContentView(R.layout.progress_layout)
dialog.show()
}
fun closeDialog() {
dialog.dismiss()
}
}
我正在显示对话框,但在响应完成时它不会关闭 ()。这到底是什么问题?
这是显示和关闭自定义弹出窗口的方法;
class ShowProgress(context: Context) : Dialog(context) {
init {
dialog = Dialog(context)
}
fun showPopup() {
val dialogview = LayoutInflater.from(context)
.inflate(R.layout.dialog_choose_image, null, false)
//initializing dialog screen
dialog?.setCancelable(true)
dialog?.setContentView(dialogview)
dialog?.show()
}
companion object{
var dialog: Dialog? = null
fun dismissPopup() = dialog?.let { dialog!!.dismiss() }
}
}
并且从视图中您可以像这样访问它。
val showProgress = ShowProgress(this) showProgress.showPopup()
并在您想关闭弹出窗口时关闭它
ShowProgress.dismissPopup()