首页 > 解决方案 > 当我使用自定义布局而不是通货膨胀时,DialogFragment 什么也不显示

问题描述

我想用自定义 ui 创建 DialogFragment。使用自己制作的自定义布局对我来说很重要。但是当从 onCreateView DialogFragment 返回一个时,什么也没有显示。顺便说一句,当在简单片段的孩子中使用相同的代码时,视图按预期显示。

override fun onCreateView(
    inflater: LayoutInflater,
    container: ViewGroup?,
    savedInstanceState: Bundle?
): View {
    val context = requireActivity()

    contentLoaderView = createContentLoaderView(context)

    return contentLoaderView
}

private fun createContentLoaderView(context: Context): ContentLoaderView{
    return ContentLoaderView(context).apply{
        attachContentView(R.layout.dialog_product_order)
        attachViewModel(viewLifecycleOwner, viewModel)
        layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
    }
}

当我使用充气机时,一切都很好。

override fun onCreateView(
    inflater: LayoutInflater,
    container: ViewGroup?,
    savedInstanceState: Bundle?
): View {
    return LayoutInflater.from(context).inflate(R.layout.dialog_product_order, container, false)
}

我究竟做错了什么?

标签: androiddialogfragment

解决方案


推荐阅读