如何使AlertDialog透明的布局背景?
我正在用Android Studio
创建一个应用程序。我创建了一个AlertDialog
,其布局的背景设置为此自定义XML:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/connectioncardColor" />
<corners android:bottomRightRadius="8dp"
android:bottomLeftRadius="8dp"
android:topRightRadius="8dp"
android:topLeftRadius="8dp"/>
<stroke
android:color="@color/colorPrimaryDark"
android:width="1dp"/>
</shape>
背景的角落很好且圆润,但背景后面是另一层白色。因此,角落里有一些白色,如何删除它?
态
I'm creating an app in Android Studio
. I created an AlertDialog
with the background of the layout set to this custom xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/connectioncardColor" />
<corners android:bottomRightRadius="8dp"
android:bottomLeftRadius="8dp"
android:topRightRadius="8dp"
android:topLeftRadius="8dp"/>
<stroke
android:color="@color/colorPrimaryDark"
android:width="1dp"/>
</shape>
The corners of the background are nice and rounded but behind the background is another layer of white. So there is bit of white in the corner, how to remove that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建对话框的自定义样式
,然后在构建器中添加此样式
Create your custom style for dialog
then add this style in builder
由于我不能仅发布一个链接,因此我也会复制答案,但是我在这里找到了答案:
如何在Android
在可绘制的可绘制中创建XML文件,例如dialog_bg.xml:
将其设置为布局xml中的背景:
将对话框的根视图的背景设置为透明,因为Android将您的对话框布局放置在隐藏在遮挡角落的根视图中您的自定义布局。
Java:
Kotlin:
Since I cant just post a link I will copy the answer too, but I found my answer here:
How to make custom dialog with rounded corners in android
Create an XML file in drawable, say dialog_bg.xml:
set it as the background in your layout XML:
Set the background of the dialog's root view to transparent, because Android puts your dialog layout within a root view that hides the corners in your custom layout.
Java:
Kotlin: