gpt4 book ai didi

android - 如何在自定义对话框布局中使用 View 绑定(bind)?

转载 作者:行者123 更新时间:2023-12-04 23:39:19 28 4
gpt4 key购买 nike

我在自定义对话框布局中实现 View 绑定(bind)时遇到问题。可能吗?

 private fun showCustomDialog(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 noBtn = dialog.findViewById(R.id.noBtn) as TextView
yesBtn.setOnClickListener {
dialog.dismiss()
}

val yesBtn = dialog.findViewById(R.id.yesBtn) as Button
noBtn.setOnClickListener { dialog.dismiss() }
dialog.show()

}

最佳答案

有可能的。

CustomDialogBinding binding = CustomDialogBinding 
.inflate(LayoutInflater.from(getContext()));
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setView(binding.getRoot());
其中 CustomDialogBinding 是自定义布局的 View 绑定(bind)文件的名称
Kotlin
val bind :CustomDialogBinding = CustomDialogBinding .inflate(inflater)
dialog.setContentView(bind.root)

关于android - 如何在自定义对话框布局中使用 View 绑定(bind)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67136040/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com