Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

android - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Started from v28 design support library we can use Material Card View, which provides us with a material styled cardview implementation out of the box.

<android.support.design.card.MaterialCardView
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_margin="10dp">
    ... child views ...
</android.support.design.card.MaterialCardView>

You can further style the cardview by using two of the attributes that come with it:

  • app:strokeColor - The colour to be used for the given stroke, this must be set in order to display a stroke
  • app:strokeWidth - The width to be applied to the stroke of the view

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...