android TextView setting the background color dynamically doesn't work ?
A1.
To set red color:
textView.setBackgroundColor(0xfff00000);
Or
<color name="solid_red">#fff00000</color>
textView.setBackgroundResource(R.color.solid_red);
A2.
if you are in activity use this
textview.setBackground(ContextCompat.getColor(this,R.color.yourcolor));
if you are in fragment use below code textview.setBackground(ContextCompat.getColor(getActivity(),R.color.yourcolor));
if your ain recyclerview adapter use below code textview.setBackground(ContextCompat.getColor(context,R.color.yourcolor));
A3.
Here are the steps to do it correctly:
|
Comments
Post a Comment