In the user view group, I have a TextView as a child. I want to set the TextView textColor based on android: value to textColor. So in res / values /styles.xml I have:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="CustomViewGroupTextView">
<attr name="android:textColor" />
</declare-styleable>
</resources>
And in the CustomViewGroup constructor, I have the following:
private TextView mTextView;
public CustomViewGroup(Context context) {
super(context);
initTextView(context, attrs);
}
public CustomViewGroup(Context context, AttributeSet attrs) {
super(context, attrs);
initTextView(context, attrs);
}
public CustomViewGroup(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initTextView(context, attrs);
}
private void initTextView(Context context, AttributeSet attrs) {
mTextView = new TextView(
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.CustomViewGroupTextView);
ColorStateList textColor = ta.getColorStateList(R.styleable.MinutiaeTextView_android_textColor);
if (textColor != null) {
mTextView.setTextColor(textColor);
}
}
My question is: how to execute mTextView.setTextColor correctly? Anyone can specify a complete list of color states or a single color value in android: textColor. Or will I get a ColorStateList with all one color if someone puts one color in android: textColor?
source
share