Source code
package android.support.v7.widget;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.Drawable;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.v4.view.TintableBackgroundView;
import android.support.v7.internal.widget.TintManager;
import android.util.AttributeSet;
import android.widget.TextView;
public class AppCompatTextView extends TextView implements TintableBackgroundView {
private AppCompatBackgroundHelper mBackgroundTintHelper;
private AppCompatTextHelper mTextHelper;
private TintManager mTintManager;
public AppCompatTextView(Context context) {
this(context, null);
}
public AppCompatTextView(Context context, AttributeSet attrs) {
this(context, attrs, 16842884);
}
public AppCompatTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.mTintManager = TintManager.get(getContext());
this.mBackgroundTintHelper = new AppCompatBackgroundHelper(this, this.mTintManager);
this.mBackgroundTintHelper.loadFromAttributes(attrs, defStyleAttr);
this.mTextHelper = AppCompatTextHelper.create(this);
this.mTextHelper.loadFromAttributes(attrs, defStyleAttr);
this.mTextHelper.applyCompoundDrawablesTints();
}
public void setBackgroundResource(@DrawableRes int resId) {
super.setBackgroundResource(resId);
if (this.mBackgroundTintHelper != null) {
this.mBackgroundTintHelper.onSetBackgroundResource(resId);
}
}
public void setBackgroundDrawable(Drawable background) {
super.setBackgroundDrawable(background);
if (this.mBackgroundTintHelper != null) {
this.mBackgroundTintHelper.onSetBackgroundDrawable(background);
}
}
public void setSupportBackgroundTintList(@Nullable ColorStateList tint) {
if (this.mBackgroundTintHelper != null) {
this.mBackgroundTintHelper.setSupportBackgroundTintList(tint);
}
}
@Nullable
public ColorStateList getSupportBackgroundTintList() {
return this.mBackgroundTintHelper != null ? this.mBackgroundTintHelper.getSupportBackgroundTintList() : null;
}
public void setSupportBackgroundTintMode(@Nullable Mode tintMode) {
if (this.mBackgroundTintHelper != null) {
this.mBackgroundTintHelper.setSupportBackgroundTintMode(tintMode);
}
}
@Nullable
public Mode getSupportBackgroundTintMode() {
return this.mBackgroundTintHelper != null ? this.mBackgroundTintHelper.getSupportBackgroundTintMode() : null;
}
public void setTextAppearance(Context context, int resId) {
super.setTextAppearance(context, resId);
if (this.mTextHelper != null) {
this.mTextHelper.onSetTextAppearance(context, resId);
}
}
protected void drawableStateChanged() {
super.drawableStateChanged();
if (this.mBackgroundTintHelper != null) {
this.mBackgroundTintHelper.applySupportBackgroundTint();
}
if (this.mTextHelper != null) {
this.mTextHelper.applyCompoundDrawablesTints();
}
}
}