Search code examples
androidmaterial-designandroid-appcompatandroid-cardview

how to set colored border on cardview


I am implementing card view but I can't find any border option to set a border on it.

here is my card.xml:

<android.support.v7.widget.CardView android:layout_marginTop="10dp"
  android:id="@+id/cardView"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  xmlns:android="http://schemas.android.com/apk/res/android"
  card_view:cardPreventCornerOverlap="false"
  app:cardPreventCornerOverlap="false"
  xmlns:card_view="http://schemas.android.com/tools"
  xmlns:app="http://schemas.android.com/apk/res-auto">

  <RelativeLayout
     android:background="@drawable/tab_bg"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:padding="16dp">

     <TextView
         android:id="@+id/title"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="Title"
         android:textSize="20sp" />

  </RelativeLayout>

</android.support.v7.widget.CardView>

here is my image that I want to implement that green border on card view?

enter image description here

Help me. How can I implement this thing? I have no clue.

Thank you.


Solution

  • Create drawable selector.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid android:color="#808080"/>
        <stroke android:width="3dp" android:color="#B1BCBE" />
        <corners android:radius="20dp"/>
        <padding android:left="0dp" android:top="0dp"
                 android:right="0dp" android:bottom="0dp" />
    </shape>      
    

    then give set this as a background, change color according your choice