I tried the code below in my adapter class, but it is not working.
myViewHolder.cardview1.setStrokeColor(ContextCompat.getColor(context, R.color.selected_color));
MaterialCardView is a customizable component based on CardView from the Android Support Library. MaterialCardView provides all of the features of CardView , but adds attributes for customizing the stroke and uses an updated Material style by default.
This method is deprecated.
I had the same problem, to solve it just add the invalidate()
method:
myViewHolder.cardview1.setStrokeColor(ContextCompat.getColor(context, R.color.selected_color));
myViewHolder.cardview1.invalidate();
This updates the view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With