在将sdk更新到Android 5.0之后,方法TextView.getTextColor(Context context, TypedArray typedArray, int defStyle)
消失了。
我在自定义TextView中使用了这个方法(用于从xml定义的int colorId
)。
那么如何从xml确定int color id
呢?
在将sdk更新到Android 5.0之后,方法TextView.getTextColor(Context context, TypedArray typedArray, int defStyle)
消失了。
我在自定义TextView中使用了这个方法(用于从xml定义的int colorId
)。
那么如何从xml确定int color id
呢?
以下是获取TextView颜色的示例代码:
TextView tv = (TextView) findViewById(R.id.yourComponentId);
int tv_color = tv.getTextColors().getDefaultColor();
TextView tv = (TextView) findViewById(R.id.yourComponentId);
int tv_color = tv.getCurrentTextColor();
如果使用第一个示例,您还可以使用以下方式获取各种状态的颜色:
TextView tv = (TextView) findViewById(R.id.yourComponentId);
ColorStateList colorStateList = tv.getTextColors();
int tv_color colorStateList.getColorForState(states, failColor);
public final ColorStateList getTextColors()