如何从 android Java Fragment 打开 Jetpack Compose 对话框

问题描述 投票:0回答:1

我有旧的片段代码,我需要从编写为可组合的片段对话框中打开:

我有这样的课:

class FullScreenDialogActivity
@JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
    AbstractComposeView(context, attrs) {
    @Composable
    override fun Content() {
      Dialog(
          title = "d",
          desc = "",
          onDismiss = {
               dialog.value = false
                     }
          )
}

但是我怎样才能从java片段类打开这样的对话框呢?

public class MyFragment extends Fragment {
@Override
    public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
   //FullScreenDialogActivity()
}
}

这个对话框应该位于片段的顶部

android dialog fragment android-jetpack composable
1个回答
0
投票

您可以从任何片段方法调用它,如下所示:

private void yourMethodOrOnClickMethodFromXml() {
        FullScreenDialogActivity dialog = new FullScreenDialogActivity(getContext());
        getActivity().setContentView(dialog);
}
© www.soinside.com 2019 - 2024. All rights reserved.