Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set color in the side of cardview

I'm trying to understand what is the best way to set color in the side of a CardView like this

enter image description here

My cardview looks like this:

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:id="@+id/cardViewWe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginTop="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp"
android:foreground="?attr/selectableItemBackground"
android:transitionName="cardTransition"
app:cardBackgroundColor="@drawable/selector"
app:cardElevation="2dp"

card_view:cardCornerRadius="8dp">

  <androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 .....
 .....
   </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
like image 226
Dioptre Pic Avatar asked Nov 21 '18 06:11

Dioptre Pic


People also ask

How do I change the color of my shadow in CardView?

Well, it is not possible to change the color of the shadow of cardview before API 28 but we can add a custom shadow behind a layout. You need to use a drawable background ( shadow. xml ) in the parent layout which is looking like a shadow. You can replace FF46A9 in shadow.

How do I customize my CardView?

Customized CardView First, add a CardView dependency to the application-level build. gradle file. Then create a drawable background for the cards. For that, create a new drawable resource file inside the drawable folder.


1 Answers

Try this way

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    app:cardCornerRadius="10dp"
    app:cardElevation="2dp"
    app:cardUseCompatPadding="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:orientation="horizontal">

        <View
            android:layout_width="5dp"
            android:layout_height="match_parent"
            android:background="@color/colorAccent" />

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical"
            android:padding="10dp">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Nilesh Rathod" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Nilesh Rathod" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Nilesh Rathod" />

        </LinearLayout>
    </LinearLayout>


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

OUTPUT

enter image description here

like image 96
AskNilesh Avatar answered Oct 13 '22 01:10

AskNilesh