Search code examples
androidandroid-cardviewmaterialcardview

Material cardView background color for child element


I am using material cardView in my application. Everything is running smoothly. I have set a background color for my cardView and child element individually. It is fine if I have one card with one child element. But I might have to add multiple cards with multiple child elements. My question is

  1. Can we make child element inherit the background color of the parent ?
  2. Or I have to set everything indidvidually ?
  3. Is it possible to give just one background color for entire cardView including child elements ?

    <com.google.android.material.card.MaterialCardView
        android:id="@+id/cardView2"
        android:layout_width="290dp"
         android:layout_height="140dp"   
         app:cardBackgroundColor="@color/Grey">
    
    <TextView
        android:id="@+id/textViewCardTown2"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:backgroundTint="@color/LightGrey"
        android:fontFamily="sans-serif"
        android:textAlignment="center"
        android:textColor="@color/colorPrimaryDark"/>
    
    </com.google.android.material.card.MaterialCardView>
    

Solution

  • You can set the background color of the child layout to transparent.

    Set:

    android:background="00000000";