无法获得全角对话框

时间:2019-02-22 15:44:17

标签: android android-dialog

我的应用程序中哪个底部滑动面板是使用自定义对话框的,但该对话框的两侧和底部都有一些空间。如何删除该空间?

这是我的代码。

自定义布局

__ORGANIZATION_ID__

自定义对话框JAVA

<LinearLayout
android:id="@+id/bottom_sheet"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:background="@color/colorPrimary"
android:paddingTop="30dp"
android:paddingBottom="30dp">

//elements of the layout

</LinearLayout>

Here is a screenshot of custom dialog

1 个答案:

答案 0 :(得分:0)

根据我的研究,对话框的默认窗口背景为abc_dialog_material_background.xml

<inset xmlns:android="http://schemas.android.com/apk/res/android"
       android:insetLeft="16dp"
       android:insetTop="16dp"
       android:insetRight="16dp"
       android:insetBottom="16dp">
    <shape android:shape="rectangle">
        <corners android:radius="@dimen/abc_dialog_corner_radius_material" />
        <solid android:color="@android:color/white" />
    </shape>
</inset>

为什么在显示对话框时看到每个站点的填充。有几种方法可以删除对话框中的所有填充。

简单的方法是为对话框的窗口背景设置颜色背景。

<style name="CustomDialog" parent="Theme.AppCompat.Dialog">
    <item name="android:windowBackground">@android:color/transparent</item>
</style>

另一种方法是为名为background_dialog.xml的对话框创建自定义背景

<inset xmlns:android="http://schemas.android.com/apk/res/android">
    <shape android:shape="rectangle">
        <corners android:radius="@dimen/abc_dialog_corner_radius_material" />
        <solid android:color="@android:color/white" />
    </shape>
</inset>

然后将其设置为style.xml文件中对话框的窗口背景。

<style name="CustomDialog" parent="Theme.AppCompat.Dialog">
    <item name="android:windowBackground">@drawable/background_dialog</item>
</style>