MainActivity.kt
package com.cfsuman.kotlintutorials
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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"
android:background="#DCDCDC"
android:id="@+id/rootLayout"
android:padding="24dp">
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/card1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:cardCornerRadius="3dp"
app:cardElevation="5dp"
app:cardMaxElevation="8dp"
app:contentPadding="40dp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Material\nCard View"
android:textSize="30sp"
android:layout_gravity="center" />
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/card2"
app:strokeWidth="2dp"
app:strokeColor="#ff3939"
app:cardBackgroundColor="#cbd4c6"
app:cardCornerRadius="3dp"
app:contentPadding="40dp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="false"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="48dp"
app:layout_constraintTop_toBottomOf="@+id/card1"
app:layout_constraintStart_toStartOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Colored Material \nCard View"
android:textSize="30sp"
android:layout_gravity="center" />
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
build.gradle dependencies[add]
// Material components
implementation 'com.google.android.material:material:1.6.1'