android如何让芯片背景透明?

How to make chip background transparent in android?

我使用的动作芯片如下:

<com.google.android.material.chip.Chip
            android:id="@+id/copyLinkChip"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/copy_link"
            app:chipIcon="@drawable/content_copy_background"
            app:chipIconTint="?attr/primaryText"
            android:textColor="?attr/primaryText"
            app:chipStrokeWidth="0.5dp"
            />

我想让它的背景完全透明怎么办?

试试这个

chip.setChipBackgroundColor(getResources().getColorStateList(android.R.color.transparent));

您可以通过 setChipBackgroundColorResource API:

以编程方式设置它
copyLinkChip.setChipBackgroundColorResource(android.R.color.transparent)

或通过XML

app:chipBackgroundColor="@android:color/transparent"

您可以在XML

中使用属性app:chipBackgroundColor
app:chipSurfaceColor="@android:color/transparent"
app:chipBackgroundColor="@android:color/transparent"