/** * Set the color used for styling the tab text. This will need to be called prior to calling * {@link #setViewPager(android.support.v4.view.ViewPager)} otherwise it will not get set * * @param color to use for tab text */ public void setDefaultTabTextColor(int color) { tabViewTextColors = ColorStateList.valueOf(color); }
int[][] states = new int[][] { new int[] { android.R.attr.state_enabled}, // enabled new int[] {-android.R.attr.state_enabled}, // disabled new int[] {-android.R.attr.state_checked}, // unchecked new int[] { android.R.attr.state_pressed} // pressed }; int[] colors = new int[] { Color.BLACK, Color.RED, Color.GREEN, Color.BLUE }; ColorStateList myList = new ColorStateList(states, colors);
public TouchableUrlSpan(String url, ColorStateList textColor, int pressedBackgroundColor) { super(url); this.normalTextColor = textColor.getDefaultColor(); this.pressedTextColor = textColor.getColorForState(STATE_PRESSED, normalTextColor); this.pressedBackgroundColor = pressedBackgroundColor; }
public RoundedDrawable setBorderColor(ColorStateList colors) { mBorderColor = colors != null ? colors : ColorStateList.valueOf(0); mBorderPaint.setColor(mBorderColor.getColorForState(getState(), DEFAULT_BORDER_COLOR)); return this; }
/** * Set the Tint ColorStateList * * @param tintStateList ColorStateList */ public void setColorStateList(ColorStateList tintStateList) { if (tintStateList == null) tintStateList = ColorStateList.valueOf(Color.BLACK); mColorStateList = tintStateList; int[] state = getState(); changeColor(tintStateList.getColorForState(state, tintStateList.getDefaultColor())); }
public void setSupportProgressTint(ColorStateList tint) { Log.e("themep", " set progress tint"); if (tint != null) { if (mProgressTintInfo == null) { mProgressTintInfo = new TintInfo(); } mProgressTintInfo.mHasTintList = true; mProgressTintInfo.mTintList = ColorStateList.valueOf(ThemeUtils.getColor(mView.getContext(), tint.getDefaultColor())); Log.e("themep", "color = " + ColorStateList.valueOf(ThemeUtils.getColor(mView.getContext(), tint.getDefaultColor())).getDefaultColor()); } applySupportProgressTint(); }
public static int getDisabledThemeAttrColor(Context context, @AttrRes int attr) { final ColorStateList csl = getThemeAttrColorStateList(context, attr); if (csl != null && csl.isStateful()) { // If the CSL is stateful, we'll assume it has a disabled state and use it return csl.getColorForState(DISABLED_STATE_SET, csl.getDefaultColor()); } else { // Else, we'll generate the color using disabledAlpha from the theme final TypedValue tv = getTypedValue(); // Now retrieve the disabledAlpha value from the theme context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, tv, true); final float disabledAlpha = tv.getFloat(); return getThemeAttrColor(context, attr, disabledAlpha); } }
@Override protected boolean onStateChange(int[] state) { int color = mColorStateList.getColorForState(state, mCurColor); if(mCurColor != color){ mCurColor = color; return true; } return false; }
public int getBorderColor() { return mBorderColor.getDefaultColor(); }
@Override public boolean isStateful() { return mBorderColor.isStateful(); }
private void setSupportIndeterminateTint(ColorStateList tint) { if (tint != null) { if (mIndeterminateTintInfo == null) { mIndeterminateTintInfo = new TintInfo(); } mIndeterminateTintInfo.mHasTintList = true; mIndeterminateTintInfo.mTintList = ColorStateList.valueOf(ThemeUtils.getColor(mView.getContext(), tint.getDefaultColor())); } applySupportIndeterminateTint(); }
int getColorForCurrentState(int defaultColor) { if (mColors != null) { return mColors.getColorForState(mState, defaultColor); } else { return defaultColor; } }
@ColorInt public int getBorderColor() { return mBorderColor.getDefaultColor(); }
@Override public boolean isStateful() { return super.isStateful() || (mTint != null && mTint.isStateful()); }
private static PorterDuffColorFilter createTintFilter(Context context, ColorStateList tint, PorterDuff.Mode tintMode, final int[] state) { if (tint == null || tintMode == null) { return null; } final int color = ThemeUtils.replaceColor(context, tint.getColorForState(state, tint.getDefaultColor())); return getPorterDuffColorFilter(color, tintMode); }
/** * Set the border color. * * @param color the color to set. * @return the builder for chaining. */ public RoundedTransformationBuilder borderColor(int color) { mBorderColor = ColorStateList.valueOf(color); return this; }
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); AppCompatButton v = (AppCompatButton) findViewById(R.id.mybutton); ColorStateList csl = new ColorStateList(new int[][]{new int[0]}, new int[]{0xffffcc00}); v.setSupportBackgroundTintList(csl); } }
private int getTrackColor(boolean checked){ mTempStates[0] = isEnabled() ? android.R.attr.state_enabled : -android.R.attr.state_enabled; mTempStates[1] = checked ? android.R.attr.state_checked : -android.R.attr.state_checked; return mTrackColors.getColorForState(mTempStates, 0); }
int getColorForCurrentState() { if (mColors != null) { return getColorForCurrentState(mColors.getDefaultColor()); } else { return Color.TRANSPARENT; } }
@Override protected void drawableStateChanged() { super.drawableStateChanged(); if (tint != null && tint.isStateful()) { updateTintColor(); } }