【发布时间】:2020-12-04 16:32:09
【问题描述】:
我正在尝试创建一个自定义的“警告”对话框,我希望它有圆角。因此,我将整个布局放入 CardView 中,并将对话框的布局设置为此布局。
但是,在深色背景上,例如默认的 Android 对话框背景,我的对话框的角落似乎出现了白色像素。
我已经尝试过建议的here,设置app:cardBackgroundColor="@color/transparent",但没有任何区别。
我的对话框布局如下(与屏幕截图不同,但按钮、bakcground 和 CardView 相同):
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 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:id="@+id/error_cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/error_dialog_margin"
android:layout_marginEnd="@dimen/error_dialog_margin"
app:cardCornerRadius="@dimen/error_dialog_corner_radius"
app:cardElevation="@dimen/error_dialog_elevation"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/error_icon"
style="@style/ErrorViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_outer_margin"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/error_icon"
android:tint="@color/redColor" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/error_title"
style="@style/ErrorViewTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/default_outer_margin"
android:layout_marginTop="@dimen/default_margin"
android:layout_marginEnd="@dimen/default_outer_margin"
android:ellipsize="end"
android:gravity="center_horizontal"
android:maxLines="2"
android:text="@string/something_went_wrong" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/error_message"
style="@style/ErrorViewMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/default_outer_margin"
android:layout_marginTop="@dimen/default_margin"
android:layout_marginEnd="@dimen/default_outer_margin"
android:gravity="center"
android:minHeight="55dp"
tools:text="@string/try_again_later" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_margin"
android:background="@color/blueColor">
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/error_ok_button"
style="@style/PrimaryButton"
android:layout_width="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:text="@string/ok_button" />
</FrameLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
请查看问题截图:
知道为什么会发生这种情况以及如何解决吗?这似乎与cardview的背景有关,因为将所有背景设置为透明可以解决问题,但我需要对话框背景为白色。
【问题讨论】:
-
你找到这个卢卡斯的解决方案了吗?
标签: android android-layout android-cardview