// Step 1: Get the CardView reference
val cardView = findViewById<CardView>(R.id.yourCardViewId)
// Step 2: Get the background drawable of the CardView
val backgroundDrawable = cardView.background
// Step 3: Check if the background is a ColorDrawable
if (backgroundDrawable is ColorDrawable) {
// Step 4: Get the color of the ColorDrawable
val backgroundColor = backgroundDrawable.color
// Now, 'backgroundColor' variable holds the color of the CardView background
} else {
// Handle the case where the background is not a ColorDrawable
// You may want to set a default color or implement a different logic here
}