DialogFragment 在 30 次后不会打开 - android

DialogFragment won't open after 30 times - android

我在对话片段中遇到了一个问题。打开 dialogfragment 30 次后,下一个模糊了屏幕但没有内容。有解决办法吗??

这是父片段:

DialogFragment newFragment = new B3Fragment();
newFragment.show(getFragmentManager(), "");

这是我的 onCreateDialog:

public Dialog onCreateDialog(Bundle savedInstanceState) {
    View view = getActivity().getLayoutInflater().inflate(R.layout.fragment_b3, new LinearLayout(getActivity()), false);

    // Build dialog
    Dialog builder = new Dialog(getActivity());
    builder.requestWindowFeature(Window.FEATURE_NO_TITLE);
    builder.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    builder.setContentView(view);
    return builder;
}

谢谢。

也许你应该使用 Dialog.Builder.create() 而不是 new Dialog()

您没有创建对话框,您必须在 return 之前创建对话框。

public Dialog onCreateDialog(Bundle savedInstanceState) {
    View view = getActivity().getLayoutInflater().inflate(R.layout.fragment_b3, new LinearLayout(getActivity()), false);

    // Build dialog
    Dialog.Builder builder = new Dialog.Builder(getActivity());
    builder.requestWindowFeature(Window.FEATURE_NO_TITLE);
    builder.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    builder.setContentView(view);
    return builder.create();
}