如何在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"
/>

我想让它的背景完全透明,怎么做呢?

您可以在XML 中使用属性app:chipBackgroundColor

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

您可以通过setChipBackgroundColorResource API:以编程方式进行设置

copyLinkChip.setChipBackgroundColorResource(android.R.color.transparent)

或通过XML

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

试试这个

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

最新更新