How can I set Text Color of a text view to #bdbdbd
programatically?
This question is related to
android
textview
background-color
Great answers. Adding one that loads the color from an Android resources xml but still sets it programmatically:
textView.setTextColor(getResources().getColor(R.color.some_color));
Please note that from API 23, getResources().getColor()
is deprecated. Use instead:
textView.setTextColor(ContextCompat.getColor(context, R.color.some_color));
where the required color is defined in an xml as:
<resources>
<color name="some_color">#bdbdbd</color>
</resources>
Update:
This method was deprecated in API level 23. Use getColor(int, Theme) instead.
Check this.
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:
yourTextView.setTextColor(color);
Or, in your case: yourTextView.setTextColor(0xffbdbdbd);
Source: Stackoverflow.com