首页 > 解决方案 > 如何编辑自定义对话框背景?

问题描述

在此处输入图像描述

我是 Android 编程新手,我还在学习我想删除这个变形的部分,但我尝试了各种方法,但都没有成功。你能帮助我吗?

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:background="@drawable/buttonshape"
    android:padding="10dp">


    <Button
        android:id="@+id/button"
        android:layout_width="42dp"
        android:layout_height="30dp"
        android:layout_marginTop="5dp"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="5dp"
        android:background="@drawable/click"
        android:text="تم"
        android:textColor="#fff"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/radioGroup"
        app:layout_constraintVertical_bias="0.27999997" />

标签: androidlayoutdialog

解决方案


简而言之,要从对话框中删除空白区域,您必须使对话框背景透明,以便它可以显示使用的区域。尝试

dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); 

或者

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

推荐阅读