android - 如何在 BottomSheetDialog 上使用 View 绑定(bind)

标签 android kotlin android-viewbinding android-bottomsheetdialog

我正在尝试在我的 MainActivity 中创建一个 BottomSheetDialog,但现在我正在使用合成来绑定(bind)我的 View 。但现在我不知道如何附加 ViewBinding给我的BottomSheetDialog .
这就是我所做的,使用合成的。

dialog = BottomSheetDialog(this, R.style.BottomDialogStyle)
dialogView = LayoutInflater.from(this).inflate(R.layout.test_dialog, dialog.mainContainer, false)
dialog.setContentView(dialogView)
这就是让我对 ViewBinding 感到困惑的地方
dialog = BottomSheetDialog(this, R.style.BottomDialogStyle)
binding = TestDialogBinding.inflate(?)
dialog.setContentView(binding.root)
从上面的示例中,我想知道应该用什么填充参数,因为与在 Activity 中我可以只用 layoutInflater 填充该参数不同。或在 RecyclerView我无法填充该参数的适配器LayoutInflater.from(parent.context), parent, and false .

最佳答案

您还可以创建一个 LayouInflater :

val inflater = LayoutInflater.from(requireContext())
然后将充气机传递给:
binding = TestDialogBinding.inflate(inflater)

关于android - 如何在 BottomSheetDialog 上使用 View 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67172338/

相关文章:

java - 如何将 TextView 数据从第一个 Activity 发送到第三个 Activity

android - MapFragment 在 DialogActivity 中使用时会出现深色覆盖

java - 如何在 Kotlin 中压缩列表并跳过下一个?

android - 试图在另一个 Activity 中将两个 EditTexts 的产品显示为 TextView

java - RecyclerView适配器类中Android View Binding的正确方式是什么?

android - 迁移到 View 绑定(bind)后 RecyclerView 项目宽度变为 wrap_content

android - ViewBinding 类未生成

android - 如何使用 viewpager 创建具有不同 ListView 项的选项卡

安卓广播接收器和双 SIM 卡

android - 在单例私有(private)构造函数类上使用 hilt 进行依赖注入(inject)