android cardview background color 적용하기


java 코드

setCardBackgroundColor 메소드를 사용하시면 됩니다.

int color = R.color.color_black;

CardView lay_frame = (CardView) itemView.findViewById(R.id.lay_frame);
lay_frame.setCardBackgroundColor(ContextCompat.getColor(getActivity(), res));


or xml 코드

cardBackgroundColor 애튜리뷰트를 사용하면 됩니다.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:foreground="?android:attr/selectableItemBackground"
    android:id="@+id/lay_frame"
    android:layout_marginTop="8dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    card_view:cardCornerRadius="5dp"
    card_view:cardBackgroundColor="@color/color_black">



+ Recent posts