android - 如何编辑自定义对话框背景?
问题描述
我是 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" />
解决方案
简而言之,要从对话框中删除空白区域,您必须使对话框背景透明,以便它可以显示使用的区域。尝试
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
或者
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
推荐阅读
- angular - Angular Typescript 订阅嵌套对象订阅
- html - 将 (img) 元素高度缩小到 flex 容器中同级元素的高度
- ruby-on-rails - 设计不允许的强参数:avatar
- python - 如何在 Python 的 DataFrame 中显示午夜时间?
- c++ - C++ 避免三指针
- amazon-web-services - 如何从 API 网关链接两个 lambda 函数
- webpack - Manipulate file contents in Webpack
- angular - 以角度显示单个项目下的详细信息
- visual-studio-code - 如何向 VS Code 资源管理器标题栏或命令面板提供仅在我的 web 视图聚焦时才处于活动状态的命令?
- java - 单个连接中的多个语句