A
A
AndreyGorlov2019-12-26 11:28:09
Android
AndreyGorlov, 2019-12-26 11:28:09

How to set color shadow for CardView?

There is a CardView which is in RecyclerView:

<?xml version="1.0" encoding="utf-8"?>
    <androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        card_view:cardBackgroundColor="@android:color/white"
        card_view:cardCornerRadius="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        card_view:cardElevation="10dp"
        card_view:cardUseCompatPadding="true"
        android:id="@+id/DutyID">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginLeft="10dp"
            android:clickable="false">
    
            <TextView
                android:id="@+id/nameText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="4dp"
                android:layout_marginTop="4dp"
                android:layout_marginEnd="4dp"
                android:fontFamily="@font/roboto"
                android:textColor="#000"
                android:clickable="false"
                android:gravity="center"
                android:text="услуга 1"
                card_view:layout_constraintEnd_toEndOf="parent"
                card_view:layout_constraintStart_toStartOf="parent"
                card_view:layout_constraintTop_toTopOf="parent" />
    
            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/constraintLayout"
                android:layout_width="88dp"
                android:layout_height="21dp"
                android:layout_marginStart="4dp"
                android:layout_marginTop="4dp"
                android:layout_marginEnd="4dp"
                android:clickable="false"
                android:foregroundGravity="center"
                card_view:layout_constraintBottom_toBottomOf="parent"
                card_view:layout_constraintEnd_toEndOf="parent"
                card_view:layout_constraintHorizontal_bias="0.0"
                card_view:layout_constraintStart_toStartOf="parent"
                card_view:layout_constraintTop_toBottomOf="@+id/nameText"
                card_view:layout_constraintVertical_bias="0.0">
    
                <TextView
                    android:id="@+id/priceText"
                    android:layout_width="wrap_content"
                    android:layout_height="0dp"
                    android:layout_marginStart="40dp"
                    android:layout_marginEnd="60dp"
                    android:clickable="false"
                    android:textColor="#000"
                    android:gravity="center|end"
                    android:text="100"
                    android:fontFamily="@font/roboto"
                    card_view:layout_constraintBottom_toBottomOf="parent"
                    card_view:layout_constraintEnd_toEndOf="parent"
                    card_view:layout_constraintStart_toStartOf="parent"
                    card_view:layout_constraintTop_toTopOf="parent" />
    
                <ImageView
                    android:id="@+id/priceImageView"
                    android:layout_width="12dp"
                    android:layout_height="12dp"
                    android:layout_marginStart="4dp"
                    android:backgroundTint="#383838"
                    android:clickable="false"
                    card_view:layout_constraintBottom_toBottomOf="parent"
                    card_view:layout_constraintStart_toEndOf="@+id/priceText"
                    card_view:layout_constraintTop_toTopOf="parent"
                    card_view:srcCompat="@drawable/ruble" />
    
            </androidx.constraintlayout.widget.ConstraintLayout>
    
        </androidx.constraintlayout.widget.ConstraintLayout>
    
    
            <androidx.constraintlayout.widget.ConstraintLayout
                android:id="@+id/constraintLayout2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity=""
                android:layout_marginRight="10dp"
                android:layout_marginBottom="10dp"
                android:clickable="false"
                card_view:layout_constraintBottom_toBottomOf="parent"
                card_view:layout_constraintEnd_toEndOf="parent"
                card_view:layout_constraintStart_toStartOf="parent">
    
                <ImageView
                    android:id="@+id/moreImageView"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_marginTop="10dp"
                    android:backgroundTintMode="add"
                    android:clickable="false"
                    card_view:layout_constraintBottom_toBottomOf="parent"
                    card_view:layout_constraintEnd_toEndOf="parent"
                    card_view:layout_constraintHorizontal_bias="0.0"
                    card_view:layout_constraintStart_toStartOf="parent"
                    card_view:layout_constraintTop_toTopOf="parent"
                    card_view:layout_constraintVertical_bias="0.0"
                    card_view:srcCompat="@drawable/sas" />
            </androidx.constraintlayout.widget.ConstraintLayout>
        </LinearLayout>

When you click on it, an event occurs and the value is set to Background:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
        <solid android:color="#FFF"/>
        <stroke android:width="1dip"  android:color="@color/colorPrimary" />
        <corners android:radius="10dp" />
    </shape>

How can I make the shadow also change color when clicked?
PS @color/colorPrimary=#FF6634

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question