0

I'm trying to make a DialogFragment like Facebook's:

https://i.stack.imgur.com/qimVC.png

However, my dialog doesn't come out fullscreen:

https://i.stack.imgur.com/NLuNe.png

Here is my DialogFragment class:

public class TestDialog extends DialogFragment {
    public TestDialog() {
        // Empty constructor required for DialogFragment
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NO_TITLE, R.style.TestDialog);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.dialog_layout, container);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Dialog dialog = super.onCreateDialog(savedInstanceState);
        dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        return dialog;
    }

    @Override
    public void onResume() {
        ViewGroup.LayoutParams params = getDialog().getWindow().getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.MATCH_PARENT;
        getDialog().getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
        super.onResume();
    }
}

Here is my theme TestDialog:

<style name="TestDialog" parent="@android:style/Theme.Dialog">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowFullscreen">false</item>
    <item name="android:windowCloseOnTouchOutside">true</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
</style>

I tried setting android:windowFullscreen to true, but that didn't help.

What can I do to make the dialog stretch to the device's full width and height (minus the status bar)?

0 Answers0