Where did the TextView.getTextColor (context context, TypedArray typedArray, int defStyle) method disappear in the new Android 5.0?
2 answers
Here is some sample code to get the color for a TextView:
TextView tv = (TextView) findViewById(R.id.yourComponentId);
int tv_color = tv.getTextColors().getDefaultColor();
or you can also get the color for plain text like this:
TextView tv = (TextView) findViewById(R.id.yourComponentId);
int tv_color = tv.getCurrentTextColor();
In the case of using the first example, you can also get the color for different states using
TextView tv = (TextView) findViewById(R.id.yourComponentId);
ColorStateList colorStateList = tv.getTextColors();
int tv_color colorStateList.getColorForState(states, failColor);
Hope it helps.
Ref: getColorForState
+2
source to share
It is indeed removed as you can see in the diff API: https://developer.android.com/sdk/api_diff/21/changes.html
You can use this option:
+1
source to share