我正在尝试在我的 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/