Advertisement
Advertisement


How to set text color to a text view programmatically


Question

How can I set Text Color of a text view to #bdbdbd programatically?

2014/07/25
1
274
7/25/2014 3:21:35 AM

Accepted Answer

Use,..

Color.parseColor("#bdbdbd");

like,

mTextView.setTextColor(Color.parseColor("#bdbdbd"));

Or if you have defined color code in resource's color.xml file than

(From API >= 23)

mTextView.setTextColor(ContextCompat.getColor(context, R.color.<name_of_color>));

(For API < 23)

mTextView.setTextColor(getResources().getColor(R.color.<name_of_color>));
2018/09/26
677
9/26/2018 7:29:10 PM


yourTextView.setTextColor(color);

Or, in your case: yourTextView.setTextColor(0xffbdbdbd);

2011/12/12

TextView tt;
int color = Integer.parseInt("bdbdbd", 16)+0xFF000000;
tt.setTextColor(color);

also

tt.setBackgroundColor(Integer.parseInt("d4d446", 16)+0xFF000000);

also

tt.setBackgroundColor(Color.parseColor("#d4d446"));

see:

Java/Android String to Color conversion

2017/05/23

Source: https://stackoverflow.com/questions/8472349
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]