Theme.AppCompat.Dialog 主题创建空(死)space

Theme.AppCompat.Dialog theme creates empty (dead) space

在我的应用程序中,我使用主题为 "Theme.AppCompat.Dialog" 的 Activity 将其显示为对话框。效果很好,但是,对话框会填满整个屏幕高度,留下很多 space 空白。为了说明我的问题,这里有一张打开对话框的图片(以非常高的分辨率更好地展示问题):

分辨率越高,这个越大space。

这是一个代码片段:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    xmlns:tools="http://schemas.android.com/tools">

    <!--This is the yellow box-->
    <LinearLayout
        android:id="@+id/dialog_button_bar"
        android:layout_alignParentBottom="true"
        style="?android:buttonBarStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        [Buttons...]
    </LinearLayout>

    <!--This is the red box-->
    <ScrollView
        android:layout_above="@id/dialog_button_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        [LinearLayout containing rows...]
    </ScrollView>

如果我删除 android:layout_alignParentBottom="true"android:layout_above="@id/dialog_button_bar" 属性,整个布局会跳到顶部,现在空的 space 在我的布局下方。

我做错了什么? :(

在 styles.xml

中创建新样式
<style name="MyCustomDialog" parent="Base.Theme.AppCompat.Light.Dialog">
    <item name="android:windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
</style>

现在 AndroidManifest.xml,将 android:theme="@style/MyCustomDialog" 添加到您的对话框 activity。

这似乎是某种有意为之的行为。标准 Android 应用程序安装对话框的行为方式似乎相同(在权限部分和按钮之间留有很多空白 space)所以我想我会保持这种方式...