private void init(Context context, AttributeSet attrs, int defStyle) { TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.TintableImageView, defStyle, 0); tint = a.getColorStateList( R.styleable.TintableImageView_tint); a.recycle(); }
/** * Retrieve the ColorStateList for the attribute at <var>index</var>. The value may be either a * single solid color or a reference to a color or complex {@link ColorStateList} description. * * @param index Index of attribute to retrieve. * @return ColorStateList for the attribute, or null if not defined. */ public static ColorStateList getColorStateList(Resources.Theme theme, TypedArray a, TypedValue[] values, int index) { if (values != null && theme != null) { TypedValue v = values[index]; if (v.type == TypedValue.TYPE_ATTRIBUTE) { TEMP_ARRAY[0] = v.data; TypedArray tmp = theme.obtainStyledAttributes(null, TEMP_ARRAY, 0, 0); try { return tmp.getColorStateList(0); } finally { tmp.recycle(); } } } if (a != null) { return a.getColorStateList(index); } return null; }
public static ColorStateList getThemeAttrColorStateList(Context context, @AttrRes int attr) { TEMP_ARRAY[0] = attr; TypedArray a = context.obtainStyledAttributes(null, TEMP_ARRAY); try { return a.getColorStateList(0); } finally { a.recycle(); } }
ColorStateList textColorApp = null; int textSize = 15; int typefaceIndex = -1; int styleIndex = -1; Resources.Theme theme = context.getTheme(); TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.CustomLabel, defStyle, 0); TypedArray appearance = null; int apResourceId = a.getResourceId(R.styleable.CustomLabel_android_textAppearance, -1); a.recycle(); if (apResourceId != -1) { appearance = theme.obtainStyledAttributes(apResourceId, new int[] { android.R.attr.textColor, android.R.attr.textSize, android.R.attr.typeface, android.R.attr.textStyle }); } if (appearance != null) { textColorApp = appearance.getColorStateList(0); textSize = appearance.getDimensionPixelSize(1, textSize); typefaceIndex = appearance.getInt(2, -1); styleIndex = appearance.getInt(3, -1); appearance.recycle(); }
@SuppressWarnings("ResourceType") @Override void loadFromAttribute(AttributeSet attrs, int defStyleAttr) { TypedArray array = mView.getContext().obtainStyledAttributes(attrs, ATTR, defStyleAttr, 0); Log.e("themep", "progress tint"); if (array.hasValue(0)) { Log.e("themep", "progress tint"); mProgressTintResId = array.getResourceId(0, 0); setSupportProgressTint(mView.getResources().getColorStateList(mProgressTintResId)); Log.e("themep", "progress tint = " + mProgressTintResId); } if (array.hasValue(1)) { Log.e("themep", "progress inter tint"); mIndeterminateTintResId = array.getResourceId(1, 0); setSupportIndeterminateTint(array.getColorStateList(1)); } array.recycle(); }
public static void initElevation(ShadowView view, TypedArray a, int[] ids) { int carbon_elevation = ids[0]; int carbon_shadowColor = ids[1]; int carbon_ambientShadowColor = ids[2]; int carbon_spotShadowColor = ids[3]; float elevation = a.getDimension(carbon_elevation, 0); view.setElevation(elevation); if (elevation > 0) AnimUtils.setupElevationAnimator(((StateAnimatorView) view).getStateAnimator(), view); view.setElevationShadowColor(a.getColorStateList(carbon_shadowColor)); if (a.hasValue(carbon_ambientShadowColor)) view.setOutlineAmbientShadowColor(a.getColorStateList(carbon_ambientShadowColor)); if (a.hasValue(carbon_spotShadowColor)) view.setOutlineSpotShadowColor(a.getColorStateList(carbon_spotShadowColor)); }
mLabelColor = a.getColorStateList(R.styleable.ChipView_labelColor); mDeleteIconColor = a.getColorStateList(R.styleable.ChipView_deleteIconColor); int deleteIconId = a.getResourceId(R.styleable.ChipView_deleteIcon, NONE); if(deleteIconId != NONE) mDeleteIcon = ContextCompat.getDrawable(mContext, deleteIconId); mBackgroundColor = a.getColorStateList(R.styleable.ChipView_backgroundColor);
/** * Initializes the constant state from the values in the typed array. */ private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException { final RippleState state = mState; // Account for any configuration changes. state.mChangingConfigurations |= TypedArrayCompat.getChangingConfigurations(a); // Extract the theme attributes, if any. state.mTouchThemeAttrs = TypedArrayCompat.extractThemeAttrs(a); final ColorStateList color = a.getColorStateList(R.styleable.RippleDrawable_android_color); if (color != null) { mState.mColor = color; } mState.mMaxRadius = a.getDimensionPixelSize( R.styleable.RippleDrawable_android_radius, mState.mMaxRadius); verifyRequiredAttributes(a); }
defStyleRes); try { setTextColor(colorAttrs.getColorStateList(0)); } finally { colorAttrs.recycle();
public static void initStroke(StrokeView strokeView, TypedArray a, int[] ids) { int carbon_stroke = ids[0]; int carbon_strokeWidth = ids[1]; View view = (View) strokeView; ColorStateList color = getDefaultColorStateList(view, a, carbon_stroke); if (color == null) color = a.getColorStateList(carbon_stroke); if (color != null) strokeView.setStroke(AnimatedColorStateList.fromList(color, animation -> view.postInvalidate())); strokeView.setStrokeWidth(a.getDimension(carbon_strokeWidth, 0)); }
public static void initRippleDrawable(RippleView rippleView, TypedArray a, int[] ids) { int carbon_rippleColor = ids[0]; int carbon_rippleStyle = ids[1]; int carbon_rippleHotspot = ids[2]; int carbon_rippleRadius = ids[3]; View view = (View) rippleView; if (view.isInEditMode()) return; ColorStateList color = getDefaultColorStateList(view, a, carbon_rippleColor); if (color == null) color = a.getColorStateList(carbon_rippleColor); if (color != null) { RippleDrawable.Style style = RippleDrawable.Style.values()[a.getInt(carbon_rippleStyle, RippleDrawable.Style.Background.ordinal())]; boolean useHotspot = a.getBoolean(carbon_rippleHotspot, true); int radius = (int) a.getDimension(carbon_rippleRadius, -1); rippleView.setRippleDrawable(RippleDrawable.create(color, style, view, useHotspot, radius)); } }
public static void initTint(TintedView view, TypedArray a, int[] ids) { int carbon_tint = ids[0]; int carbon_tintMode = ids[1]; int carbon_backgroundTint = ids[2]; int carbon_backgroundTintMode = ids[3]; int carbon_animateColorChanges = ids[4]; if (a.hasValue(carbon_tint)) { ColorStateList color = getDefaultColorStateList((View) view, a, carbon_tint); if (color == null) color = a.getColorStateList(carbon_tint); if (color != null) view.setTintList(AnimatedColorStateList.fromList(color, animation -> ((View) view).postInvalidate())); } view.setTintMode(TintedView.modes[a.getInt(carbon_tintMode, 1)]); if (a.hasValue(carbon_backgroundTint)) { ColorStateList color = getDefaultColorStateList((View) view, a, carbon_backgroundTint); if (color == null) color = a.getColorStateList(carbon_backgroundTint); if (color != null) view.setBackgroundTintList(AnimatedColorStateList.fromList(color, animation -> ((View) view).postInvalidate())); } view.setBackgroundTintMode(TintedView.modes[a.getInt(carbon_backgroundTintMode, 1)]); if (a.hasValue(carbon_animateColorChanges)) view.setAnimateColorChangesEnabled(a.getBoolean(carbon_animateColorChanges, false)); }
textAllCaps = a.getBoolean( R.styleable.stl_SmartTabLayout_stl_defaultTabTextAllCaps, textAllCaps); textColors = a.getColorStateList( R.styleable.stl_SmartTabLayout_stl_defaultTabTextColor); textSize = a.getDimension(
public Builder(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RadioButtonDrawable, defStyleAttr, defStyleRes); width(a.getDimensionPixelSize(R.styleable.RadioButtonDrawable_rbd_width, ThemeUtil.dpToPx(context, 32))); height(a.getDimensionPixelSize(R.styleable.RadioButtonDrawable_rbd_height, ThemeUtil.dpToPx(context, 32))); strokeSize(a.getDimensionPixelSize(R.styleable.RadioButtonDrawable_rbd_strokeSize, ThemeUtil.dpToPx(context, 2))); radius(a.getDimensionPixelSize(R.styleable.RadioButtonDrawable_rbd_radius, ThemeUtil.dpToPx(context, 10))); innerRadius(a.getDimensionPixelSize(R.styleable.RadioButtonDrawable_rbd_innerRadius, ThemeUtil.dpToPx(context, 5))); strokeColor(a.getColorStateList(R.styleable.RadioButtonDrawable_rbd_strokeColor)); animDuration(a.getInt(R.styleable.RadioButtonDrawable_rbd_animDuration, context.getResources().getInteger(android.R.integer.config_mediumAnimTime))); a.recycle(); if(mStrokeColor == null){ int[][] states = new int[][]{ new int[]{-android.R.attr.state_checked}, new int[]{android.R.attr.state_checked}, }; int[] colors = new int[]{ ThemeUtil.colorControlNormal(context, 0xFF000000), ThemeUtil.colorControlActivated(context, 0xFF000000), }; strokeColor(new ColorStateList(states, colors)); } }
public Builder(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CheckBoxDrawable, defStyleAttr, defStyleRes); width(a.getDimensionPixelSize(R.styleable.CheckBoxDrawable_cbd_width, ThemeUtil.dpToPx(context, 32))); height(a.getDimensionPixelSize(R.styleable.CheckBoxDrawable_cbd_height, ThemeUtil.dpToPx(context, 32))); boxSize(a.getDimensionPixelSize(R.styleable.CheckBoxDrawable_cbd_boxSize, ThemeUtil.dpToPx(context, 18))); cornerRadius(a.getDimensionPixelSize(R.styleable.CheckBoxDrawable_cbd_cornerRadius, ThemeUtil.dpToPx(context, 2))); strokeSize(a.getDimensionPixelSize(R.styleable.CheckBoxDrawable_cbd_strokeSize, ThemeUtil.dpToPx(context, 2))); strokeColor(a.getColorStateList(R.styleable.CheckBoxDrawable_cbd_strokeColor)); tickColor(a.getColor(R.styleable.CheckBoxDrawable_cbd_tickColor, 0xFFFFFFFF)); animDuration(a.getInt(R.styleable.CheckBoxDrawable_cbd_animDuration, context.getResources().getInteger(android.R.integer.config_mediumAnimTime))); a.recycle(); if(mStrokeColor == null){ int[][] states = new int[][]{ new int[]{-android.R.attr.state_checked}, new int[]{android.R.attr.state_checked}, }; int[] colors = new int[]{ ThemeUtil.colorControlNormal(context, 0xFF000000), ThemeUtil.colorControlActivated(context, 0xFF000000), }; strokeColor(new ColorStateList(states, colors)); } }
mHorizontalPadding = a.getDimensionPixelOffset(com.rey.material.demo.R.styleable.WeekView_wv_horizontalPadding, ThemeUtil.dpToPx(context, 8)); int animDuration = a.getInteger(com.rey.material.demo.R.styleable.WeekView_wv_animDuration, context.getResources().getInteger(android.R.integer.config_mediumAnimTime)); mBackgroundColors = a.getColorStateList(com.rey.material.demo.R.styleable.WeekView_wv_backgroundColor);
mBorderColor = a.getColorStateList(R.styleable.RoundedImageView_riv_border_color); if (mBorderColor == null) { mBorderColor = ColorStateList.valueOf(RoundedDrawable.DEFAULT_BORDER_COLOR);
mNameView.setEllipsize(TextUtils.TruncateAt.END); int nameTextSize = a.getDimensionPixelSize(R.styleable.ContactView_cv_nameTextSize, 0); ColorStateList nameTextColor = a.getColorStateList(R.styleable.ContactView_cv_nameTextColor); int nameTextAppearance = a.getResourceId(R.styleable.ContactView_cv_nameTextAppearance, 0); if(nameTextAppearance > 0) mAddressView.setEllipsize(TextUtils.TruncateAt.END); int addressTextSize = a.getDimensionPixelSize(R.styleable.ContactView_cv_addressTextSize, 0); ColorStateList addressTextColor = a.getColorStateList(R.styleable.ContactView_cv_addressTextColor); int addressTextAppearance = a.getResourceId(R.styleable.ContactView_cv_addressTextAppearance, 0); if(addressTextAppearance > 0)
text.set(a.getString(attr)); } else if (attr == R.styleable.Text_android_textColor) { textColorStateList.set(a.getColorStateList(attr)); } else if (attr == R.styleable.Text_android_textSize) { textSize.set(a.getDimensionPixelSize(attr, 0));
int intervalSize = a.getDimensionPixelOffset(R.styleable.CheckBox_gIntervalSize, baseSize); int markSize = a.getDimensionPixelOffset(R.styleable.CheckBox_gMarkSize, -1); ColorStateList color = a.getColorStateList(R.styleable.CheckBox_gMarkColor); String fontFile = a.getString(R.styleable.CheckBox_gFont);