Where did the TextView.getTextColor (context context, TypedArray typedArray, int defStyle) method disappear in the new Android 5.0?

After updating sdk to Android 5.0, technology disappeared TextView.getTextColor(Context context, TypedArray typedArray, int defStyle)

.
I used this method for my custom TextView (to be defined int colorId

from xml).
So how to determine int color id

from xml?

+3


source to share


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


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:



public final ColorStateList getTextColors()

+1


source







All Articles