How to change background colour of card view itam?

Viewed 35

I tried to give the background colour of card view item when they are clicked the colour are set the new activity are open but then back pressed the card item background colour are not set.

if (!arrayListBusinessList.get ( position ).equals ( "" )){
     holder.cardViewBusinessListItem.setCardBackgroundColor ( ContextCompat.getColor ( context,R.color.green ) );
                        lastVisited ( true,position );
}
2 Answers

Try this you can use both color code or color directory path

holder.cardViewBusinessListItem.setBackgroundColor(Color.parseColor("#00FF00"));

Card view has a lot of problems. You should instead change the background of the parent view that is inside card view.

<CardView>
    <RelativeLayout> <-- change this view's background instead
        <ABC.../>
        <XYZ.../>
    </RelativeLayout>
</CardView>
Related