Android Tag/Badge Widget With Material Chip

May 1, 2020

Enable Android Enable Material Design.

<com.google.android.material.chip.Chip
    android:id="@+id/batchStatusChip"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Success"
    />

Change color

<com.google.android.material.chip.Chip
    android:id="@+id/batchStatusChip"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Success"
    android:layout_gravity="right"
    app:chipBackgroundColor="@color/success_chip"
    android:textColor="@android:color/white"
    />

Change color programatically

batchStatusChip.chipBackgroundColor = getColorStateList(context, R.color.success_chip)

res/values/colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="success_chip">#01DF3A</color>
    <color name="fail_chip">#FA5858</color>
</resources>

NOTE: Refer Android Tag Input/EditText (Material Chips)

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.