<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout 

    xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    tools:context=".MainActivity">

  

    <androidx.cardview.widget.CardView

        android:id="@+id/cardView"

        android:layout_width="match_parent"

        android:layout_height="190dp"

        android:layout_centerInParent="true"

        app:cardCornerRadius="22dp"

        app:cardUseCompatPadding="true"

        app:cardElevation="4dp"

        android:foreground="@drawable/purple_bg"

        android:clickable="true" >

  

        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="match_parent"

            android:background="@drawable/silver_bg">

        </LinearLayout>

  

    </androidx.cardview.widget.CardView>

  

    <TextView

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_below="@+id/cardView"

        android:gravity="center"

        android:text="Changing Card Color on Click"

        android:textStyle="bold|italic"

        android:textColor="#2F8C46"

        android:textSize="20sp" />

  

</RelativeLayout>

Step 5: Working with the MainActivity.java file

Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file.

Java

package com.anas.gfghover;

  

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

  

public class MainActivity extends AppCompatActivity {

  

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

    }

}

How to Change CardView Color When Selected in Android?

استفاده از ریسیکل ویو در اندروید

تعیین یک عکس قرار گرفته در حافظه خارجی (External Storage) به عنوان عکس پس زمینه گوشی

تبدیل رادیان (Radian) به درجه (Degree)، با روش Math.toDegrees ، در برنامه نویسی اندروید

عیب یابی گوشی

the mainactivity ,     ,the mainactivity java file
مشخصات