Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set border color for a chip in Android

In my android app I have a simple chip that looks like this.

enter image description here

Is there any way to set the color of the border to make it like this?

enter image description here

UPDATE: I tried to do add the shape but there's an exception during inflating the layout

 <android.support.design.chip.Chip
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:background="@drawable/chip_with_border"
     android:text="my chip" />

drawable/chip_with_border.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#FFFFFF"/>
            <corners android:radius="30dp"/>
            <stroke android:width="1dp" android:color="#DDDDDD"/>
        </shape>
    </item>
</selector>

This causes the exception

android.view.InflateException: Binary XML file line #32: Error inflating class android.support.design.chip.Chip

like image 270
Vitalii Avatar asked Mar 22 '19 18:03

Vitalii


1 Answers

I found the answer myself. I need to add chipStrokeColor and chipStrokeWidth attributes to my chip

  <android.support.design.chip.Chip
      android:id="@+id/chip"
      style="@style/Widget.MaterialComponents.Chip.Filter"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      app:chipStrokeColor="#F0F"
      app:chipStrokeWidth="1dp"
      android:text="my chip"
      app:checkedIcon="@drawable/ic_done_green"
      app:chipBackgroundColor="#FFF" />

enter image description here

like image 86
Vitalii Avatar answered Sep 20 '22 19:09

Vitalii