如何通过xml在屏幕底部设置Android DialogFragment?

How to set Android DialogFragment in screen bottom by xml?

我可以通过java在屏幕底部设置DialogFragment,像这样

public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        setStyle(STYLE_NO_TITLE, R.style.DialogBottom);
        Dialog dialog = super.onCreateDialog(savedInstanceState);
        Window window = dialog.getWindow();
        if (window != null) {
            window.setGravity(Gravity.BOTTOM);
        }
        return dialog;
    }

但我想通过 xml 设置它,例如:

<style name="DialogBottom" parent="Theme.AppCompat.Dialog.Alert">
        <item name="android:windowBackground">@null</item>
        <item name="android:windowMinWidthMinor">100%</item>
        <item name="android:windowMinWidthMajor">100%</item>
        <!--which attr can set Dialog in screen bottom ???-->
    </style>

但是我不知道是哪个属性...

不幸的是,XML 无法做到这一点。 BottomSheetDialog class 就是为此目的而设计的。

你可以看看这个 Medium post 如何使用它:https://medium.com/@wise4rmgodadmob/a-simple-example-of-using-bottomsheetdialog-in-android-development-using-kotlin-152be3b29737