How can I convert Color to Drawable to programmatically set the background for the view ? There is no setColorBackground() method.
|
2 answers
The answer is found, as if by order there is a beautiful ColorDrawable object that receives color from xml and works as a full-fledged Drawable
|
The view has a setBackgroungColor(); method setBackgroungColor();
As an example: setBackgroungColor(Color.parseColor("#FF00FF"));
Or from resources:
setBackgroundColor(ContextCompat.getColor(context, R.color.colorWhite));
setBackground(ContextCompat.getDrawable(context, R.drawable.custom_draw)); - I wrote that he is not there, well, more precisely not that he is not, but he is not a worker. You need to specifically specify Color as Drawable - Pasha Doncov
- @PashaDoncov this method works fine for
view, if you have a specific or custom component - specify it - zTrap - Maybe you need something like this? view.setBackground (getResources (). getDrawable (R.color.black)); - Eugene Troyanskii
- @EugeneTroyanskii yes - Pasha Doncov
|