【问题标题】:How to make chip background transparent in android?如何在android中使芯片背景透明?
【发布时间】:2021-05-27 13:07:32
【问题描述】:

我正在使用像这样的动作芯片:

<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"
            />

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

【问题讨论】:

    标签: android material-design android-chips


    【解决方案1】:

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

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

    或通过 XML

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

    【讨论】:

    • 有什么办法可以通过xml实现吗?
    • app:chipBackgroundColor="@null" 呢?
    • @ChaitanyaKarmarkar 请参考我的更新答案
    • 我们也可以设置 app:chipBackgroundColor="@null" 使其背景透明吗?
    【解决方案2】:

    试试这个

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

    【讨论】:

    • 有什么办法可以通过xml实现吗?
    • app:chipBackgroundColor="@null" 呢?
    【解决方案3】:

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

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

    【讨论】:

    • 如果我使用 app:chipSurfaceColor="@android:color/transparent" 那么它会掩盖涟漪效应。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-16
    • 2021-01-07
    • 2011-09-24
    • 2012-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多