简体   繁体   English

DialogFragment 不显示自定义布局

[英]DialogFragment not showing custom layout

I have a DialogFragment with a custom layout.我有一个带有自定义布局的 DialogFragment。 Everything shows properly when the fragment is embedded in my activity using a FragmentTransaction, like so:当片段使用 FragmentTransaction 嵌入到我的活动中时,一切都会正确显示,如下所示:

        getSupportFragmentManager()
        .beginTransaction()
        .add(
            R.id.fragment_container,
            exampleDialogFragment,
            ExampleDialogFragment.TAG)
        .commit();

but when I do:但是当我这样做时:

        exampleDialogFragment.show(getSupportFragmentManager(), exampleDialogFragment.TAG);

the dialog only shows the 'Cancel' button.该对话框仅显示“取消”按钮。 The stuff in the custom layout doesn't appear.自定义布局中的内容不会出现。

This is what my ExampleDialogFragment class looks like:这就是我的 ExampleDialogFragment class 的样子:

public class ExampleDialogFragment extends DialogFragment {

    @Override
    public View onCreateView(
     @NonNull LayoutInflater layoutInflater,
     @Nullable ViewGroup viewGroup,
     @Nullable Bundle bundle) {
          // Inflate layout and init views
  }

This documentation https://developer.android.com/guide/topics/ui/dialogs#FullscreenDialog seems to imply that we don't need to override onCreateDialog , so I'm not doing that.该文档https://developer.android.com/guide/topics/ui/dialogs#FullscreenDialog似乎暗示我们不需要覆盖onCreateDialog ,所以我不这样做。 However, it still doesn't look right.但是,它看起来仍然不正确。 Am I missing something?我错过了什么吗?

For anyone looking at this, my dialog had an outer ConstraintLayout.对于任何看到这个的人,我的对话框都有一个外部 ConstraintLayout。 Changing it to a RelativeLayout fixed the issue.将其更改为 RelativeLayout 解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的 DialogFragment 没有显示自定义布局? - Why is my DialogFragment not showing the custom layout? Android:DialogFragment 的自定义布局没有像 AlertDialog 那样完全显示其宽度 - Android: Custom layout for DialogFragment is not showing fully in it's width like AlertDialog ViewFlipper未显示在自定义DialogFragment中 - ViewFlipper not showing in custom DialogFragment DialogFragment中的Kotlin合成和自定义布局 - Kotlin synthetic and custom layout in DialogFragment DialogFragment:将AlertDialog与自定义布局一起使用 - DialogFragment : Using AlertDialog with custom layout DialogFragment 已触发,但未在 Navigation Architecture 组件中显示布局 - DialogFragment Triggered, but not showing the layout In Navigation Architecture component 具有自定义布局的DialogFragment会导致我的应用程序崩溃 - DialogFragment with a custom layout causes a crash in my application 无法动态更改自定义DialogFragment布局 - Can't change a Custom DialogFragment layout dynamically DialogFragment onCreateView不返回自定义布局视图? - DialogFragment onCreateView not returning custom layout view? 在 Kotlin 中使用自定义布局查看 DialogFragment 中的绑定 - View Binding in DialogFragment with custom layout in Kotlin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM