首页 > 解决方案 > 如何在 Compose 中创建 DialogFragment?

问题描述

我正在将我的应用程序转换为 Compose,

class BinDetailDialogFragment  //private View pic;
: DialogFragment() {
   override fun onCreateView(
    inflater: LayoutInflater,
    container: ViewGroup?,
    savedInstanceState: Bundle?
): View? {
    return ComposeView(requireContext()).apply {
        setContent {
            Text(
                text = "This is Recipe Fragment",
                style = TextStyle(
                    fontSize = TextUnit.Sp(21)
                )
            )
        }
    }
 }
}

当我打开对话框片段时:

    activity?.supportFragmentManager?.let {
    BinDetailDialogFragment.newInstance().show(it, BinDetailDialogFragment.TAG)
}

它抛出

java.lang.NoSuchMethodError: No virtual method setContent(Lkotlin/jvm/functions/Function0;)V in class Landroidx/compose/ui/platform/ComposeView; or its super classes (declaration of 'androidx.compose.ui.platform.ComposeView' appears in

标签: android-jetpackandroid-jetpack-compose

解决方案


推荐阅读