[英]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.