Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When I change the background of a Card view, the corner radius is reset

The situation is that when I modify a Card view background from a program then the corner radius of the Card view reset. But why?
(I don't think I need to provide any other information (code, picture of the result, etc.), because I think it's clear enough to understand. If you need more information then you should write down in a comment.)

like image 624
Noel Nemeth Avatar asked Apr 14 '18 22:04

Noel Nemeth


2 Answers

If you try to use CardView with corner radius you will face this problem when you set background color dynamically. Please use yourCardView.setCardBackgroundColor() methord instead of yourCardView.setBackgroundColor() :)

like image 136
Dulanga Avatar answered Sep 30 '22 08:09

Dulanga


I found a solution to the question.
I needed to retrieve the background of the view and set its color, then I assigned the new background to the view.

Drawable backgroundOff = v.getBackground(); //v is a view
backgroundOff.setTint(defaultColor); //defaultColor is an int 
v.setBackground(backgroundOff);

(This answer helped: https://stackoverflow.com/a/18394982/9377499)

like image 43
Noel Nemeth Avatar answered Sep 30 '22 10:09

Noel Nemeth