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

时间:2016-11-02 10:35:14

标签: android dialog themes

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

enter image description here

分辨率越高,此空间越大。

以下是代码段:

<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"属性,整个布局会跳到顶部,现在空白区域位于我的布局下方。

我做错了什么? :(

2 个答案:

答案 0 :(得分:1)

这似乎是某种预期的行为。标准的Android应用程序安装对话框的行为似乎相同(在权限部分和按钮之间留下了很多空白区域),所以我想我会这样做......

答案 1 :(得分:0)

在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 =&#34; @ style / MyCustomDialog&#34;到您的Dialog活动。