In XML, we can set a text color by the textColor
attribute, like android:textColor=\"#FF0000\"
. But how do I change it by coding?
I tried s
You can use
holder.text.setTextColor(Color.rgb(200,0,0));
You can also specify what color you want with Transparency.
holder.text.setTextColor(Color.argb(0,200,0,0));
a for Alpha (Transparent) value r-red g-green b-blue
In Adapter you can set the text color by using this code:
holder.my_text_view = (TextView) convertView.findViewById(R.id.my_text_view);
holder.my_text_view.setTextColor(Color.parseColor("#FFFFFF"));
TextView textresult = (TextView)findViewById(R.id.textView1);
textresult.setTextColor(Color.GREEN);
And another one:
TextView text = (TextView) findViewById(R.id.text);
text.setTextColor(Color.parseColor("#FFFFFF"));
Use:
TextView tv = new TextView(this);
tv.setTextColor(Color.rgb(285,0,0));
In order to set color of a TextView, TextView.setTextColor(R.color.YOURCOLOR)
is not enough!
It has to be used like this –
TextView myText = (TextView) findViewById(R.id.YoutTextViewID);
myText.setTextColor(getResources().getColor(R.color.YOURCOLOR);
OR
myText.setTextColor(Color.parseColor("#54D66A"));