在 Android 中移除 CardView 圆角半径背景

Remove CardView corner radius background in Android

我正在为 PopupWindow 视图使用 CardView 布局。 我希望布局具有圆角并且它可以工作,问题是显示了其余的角(进行圆角切割的地方):

我想去除黑角,只去除圆角,我以前这样做过,但出于某种原因,在这种情况下我无法去除。 我试过了:

card_view:cardPreventCornerOverlap="false"
card_view:cardUseCompatPadding="true"

但是没有用。 我也尝试过将布局背景设置为透明,但还是不行。

这是代码:


<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:card_view="http://schemas.android.com/tools"
    app:cardCornerRadius="8dp"
    card_view:cardPreventCornerOverlap="false"
    card_view:cardUseCompatPadding="true">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white">

        <ImageButton
            android:id="@+id/delete"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="8dp"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_delete"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/share"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageButton
            android:id="@+id/share"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="8dp"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_share"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toEndOf="@+id/delete"
            app:layout_constraintTop_toTopOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>

在@ADM 的帮助下,问题出在弹出 window 设置中,而不是布局本身。

因此,在弹出窗口初始化中添加以下行解决了问题:

popup.setBackgroundDrawable(ColorDrawable(android.graphics.Color.TRANSPARENT))