use of android.content.res.ColorStateList in project Android-skin-support by ximsfei.
the class SkinCompatResources method getColorStateList.
public ColorStateList getColorStateList(int resId) {
ColorStateList colorStateList = ContextCompat.getColorStateList(mAppContext, resId);
if (isDefaultSkin) {
return colorStateList;
}
String resName = mAppContext.getResources().getResourceEntryName(resId);
int targetResId = mResources.getIdentifier(resName, "color", mSkinPkgName);
return targetResId == 0 ? colorStateList : mResources.getColorStateList(targetResId);
}
use of android.content.res.ColorStateList in project Android-skin-support by ximsfei.
the class SkinCompatBackgroundHelper method applySkin.
public void applySkin() {
mBackgroundResId = checkResourceId(mBackgroundResId);
if (mBackgroundResId == INVALID_ID) {
return;
}
String typeName = mView.getResources().getResourceTypeName(mBackgroundResId);
if ("color".equals(typeName)) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
int color = SkinCompatResources.getInstance().getColor(mBackgroundResId);
mView.setBackgroundColor(color);
} else {
ColorStateList colorStateList = SkinCompatResources.getInstance().getColorStateList(mBackgroundResId);
Drawable drawable = mView.getBackground();
DrawableCompat.setTintList(drawable, colorStateList);
ViewCompat.setBackground(mView, drawable);
}
} else if ("drawable".equals(typeName)) {
Drawable drawable = SkinCompatResources.getInstance().getDrawable(mBackgroundResId);
ViewCompat.setBackground(mView, drawable);
} else if ("mipmap".equals(typeName)) {
Drawable drawable = SkinCompatResources.getInstance().getMipmap(mBackgroundResId);
ViewCompat.setBackground(mView, drawable);
}
}
use of android.content.res.ColorStateList in project Android-skin-support by ximsfei.
the class SkinCompatTextHelper method applyTextColorResource.
private void applyTextColorResource() {
mTextColorResId = checkResourceId(mTextColorResId);
if (mTextColorResId == R.color.abc_primary_text_disable_only_material_light || mTextColorResId == R.color.abc_secondary_text_material_light) {
return;
}
if (mTextColorResId != INVALID_ID) {
ColorStateList color = SkinCompatResources.getInstance().getColorStateList(mTextColorResId);
mView.setTextColor(color);
}
}
use of android.content.res.ColorStateList in project Android-skin-support by ximsfei.
the class SkinCompatTextHelper method applyTextColorHintResource.
private void applyTextColorHintResource() {
mTextColorHintResId = checkResourceId(mTextColorHintResId);
if (mTextColorHintResId == R.color.abc_hint_foreground_material_light) {
return;
}
if (mTextColorHintResId != INVALID_ID) {
ColorStateList color = SkinCompatResources.getInstance().getColorStateList(mTextColorHintResId);
mView.setHintTextColor(color);
}
}
use of android.content.res.ColorStateList in project platform_frameworks_base by android.
the class TextView method setTextAppearance.
/**
* Sets the text color, size, style, hint color, and highlight color
* from the specified TextAppearance resource.
*
* @deprecated Use {@link #setTextAppearance(int)} instead.
*/
@Deprecated
public void setTextAppearance(Context context, @StyleRes int resId) {
final TypedArray ta = context.obtainStyledAttributes(resId, R.styleable.TextAppearance);
final int textColorHighlight = ta.getColor(R.styleable.TextAppearance_textColorHighlight, 0);
if (textColorHighlight != 0) {
setHighlightColor(textColorHighlight);
}
final ColorStateList textColor = ta.getColorStateList(R.styleable.TextAppearance_textColor);
if (textColor != null) {
setTextColor(textColor);
}
final int textSize = ta.getDimensionPixelSize(R.styleable.TextAppearance_textSize, 0);
if (textSize != 0) {
setRawTextSize(textSize);
}
final ColorStateList textColorHint = ta.getColorStateList(R.styleable.TextAppearance_textColorHint);
if (textColorHint != null) {
setHintTextColor(textColorHint);
}
final ColorStateList textColorLink = ta.getColorStateList(R.styleable.TextAppearance_textColorLink);
if (textColorLink != null) {
setLinkTextColor(textColorLink);
}
final String fontFamily = ta.getString(R.styleable.TextAppearance_fontFamily);
final int typefaceIndex = ta.getInt(R.styleable.TextAppearance_typeface, -1);
final int styleIndex = ta.getInt(R.styleable.TextAppearance_textStyle, -1);
setTypefaceFromAttrs(fontFamily, typefaceIndex, styleIndex);
final int shadowColor = ta.getInt(R.styleable.TextAppearance_shadowColor, 0);
if (shadowColor != 0) {
final float dx = ta.getFloat(R.styleable.TextAppearance_shadowDx, 0);
final float dy = ta.getFloat(R.styleable.TextAppearance_shadowDy, 0);
final float r = ta.getFloat(R.styleable.TextAppearance_shadowRadius, 0);
setShadowLayer(r, dx, dy, shadowColor);
}
if (ta.getBoolean(R.styleable.TextAppearance_textAllCaps, false)) {
setTransformationMethod(new AllCapsTransformationMethod(getContext()));
}
if (ta.hasValue(R.styleable.TextAppearance_elegantTextHeight)) {
setElegantTextHeight(ta.getBoolean(R.styleable.TextAppearance_elegantTextHeight, false));
}
if (ta.hasValue(R.styleable.TextAppearance_letterSpacing)) {
setLetterSpacing(ta.getFloat(R.styleable.TextAppearance_letterSpacing, 0));
}
if (ta.hasValue(R.styleable.TextAppearance_fontFeatureSettings)) {
setFontFeatureSettings(ta.getString(R.styleable.TextAppearance_fontFeatureSettings));
}
ta.recycle();
}
Aggregations