2 votes

Cardview only shows the background on Android 10

I am applying a BackgroundColor to my cardview, but it only shows on Android 10, I have tested it in previous versions and it only shows transparent when actually the background color is gray.

 <androidx.cardview.widget.CardView
    android:id="@+id/cardView"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_marginStart="130dp"
    android:layout_marginTop="260dp"
    app:cardBackgroundColor="@color/LightGrey"
    app:cardMaxElevation="0dp"
    app:cardCornerRadius="80dp">

    <ImageView
        android:id="@+id/photo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@drawable/ic_camara_fotografica_20" />

</androidx.cardview.widget.CardView>

1voto

Osdward Points 88

I have solved the problem, I did it on a schedule like this:

  CardView card = view.findViewById(R.id.roundCardView);
 card.setCardBackgroundColor(Color.parseColor("#D3D3D3"));
 card.setMaxCardElevation((float) 0);
 card.setRadius((float) 50); 

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X