List of usage examples for android.content.res ColorStateList valueOf
@NonNull public static ColorStateList valueOf(@ColorInt int color)
From source file:Main.java
public static ColorStateList GetColorStateListFromHex(String hexValue) { int colorAsInt = Color.parseColor(hexValue); return ColorStateList.valueOf(colorAsInt); }
From source file:Main.java
@NonNull public static Drawable getAdaptiveRippleDrawable(int normalColor) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return new RippleDrawable(ColorStateList.valueOf(darker(normalColor)), getRippleMask(normalColor), null);// w ww . jav a2 s .c o m } else { return getStateListDrawable(normalColor, darker(normalColor)); } }
From source file:com.lambdasoup.quickfit.util.ui.BackgroundTintListAnimator.java
public static ObjectAnimator create(@NonNull Context context, @NonNull Object target, @ColorRes int startColor, @ColorRes int endColor, long duration) { ColorStateList startColorStateList = ColorStateList.valueOf(ContextCompat.getColor(context, startColor)); ColorStateList endColorStateList = ColorStateList.valueOf(ContextCompat.getColor(context, endColor)); ObjectAnimator animator = ObjectAnimator.ofObject(target, "backgroundTintList", ColorStateListEvaluator.INSTANCE, startColorStateList, endColorStateList); animator.setDuration(duration);/*w w w .java 2s. c om*/ return animator; }
From source file:net.xpece.android.colorpicker.ColorStateDrawable.java
public static Drawable create(Drawable[] layers, int color, int pressed) { if (Build.VERSION.SDK_INT >= 21) { LayerDrawable ld = new LayerDrawable(layers); ld.setColorFilter(color, PorterDuff.Mode.SRC_IN); RippleDrawable rd = new RippleDrawable(ColorStateList.valueOf(pressed), ld, null); return rd; } else {//from w w w. j a v a2 s .c om return new ColorStateDrawable(layers, color, pressed); } }
From source file:com.bobomee.android.common.util.EditUtil.java
/** * EditText ?//w w w .j a v a 2 s. com */ public static void tintEditText(EditText editText, int color) { final Drawable originalDrawable = editText.getBackground(); final Drawable wrappedDrawable = tintDrawable(originalDrawable, ColorStateList.valueOf(color)); editText.setBackgroundDrawable(wrappedDrawable); }
From source file:com.bilibili.magicasakura.utils.ColorStateListUtils.java
static ColorStateList createColorStateList(Context context, int resId) { if (resId <= 0) return null; TypedValue value = new TypedValue(); context.getResources().getValue(resId, value, true); ColorStateList cl = null;/* w ww .j a va 2s.c o m*/ if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) { //Assume that "color/theme_color_primary" and "color/theme_color_profile" have the same color value; //However, "color/theme_color_primary" need to replace by themeId, "color/theme_color_profile" not. //If use value.data may cause "color/theme_color_profile" still been replaced by themeId cl = ColorStateList.valueOf(ThemeUtils.replaceColorById(context, value.resourceId)); } else { final String file = value.string.toString(); try { if (file.endsWith("xml")) { final XmlResourceParser rp = context.getResources().getAssets() .openXmlResourceParser(value.assetCookie, file); final AttributeSet attrs = Xml.asAttributeSet(rp); int type; while ((type = rp.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { // Seek parser to start tag. } if (type != XmlPullParser.START_TAG) { throw new XmlPullParserException("No start tag found"); } cl = createFromXmlInner(context, rp, attrs); rp.close(); } } catch (IOException e) { e.printStackTrace(); } catch (XmlPullParserException e) { e.printStackTrace(); } } return cl; }
From source file:com.ww.administrator.demotest.util.ViewUtil.java
public static RippleDrawable createRipple(@ColorInt int color, @FloatRange(from = 0f, to = 1f) float alpha, boolean bounded) { color = ColorUtil.modifyAlpha(color, alpha); return new RippleDrawable(ColorStateList.valueOf(color), null, bounded ? new ColorDrawable(Color.WHITE) : null); }
From source file:liam.franco.selene.ui.ToolsBarImageView.java
@Override public void setSelected(boolean selected) { super.setSelected(selected); setImageTintList(selected ? ColorStateList.valueOf(ContextCompat.getColor(App.CONTEXT, R.color.accent)) : ColorStateList.valueOf(defaultTint)); }
From source file:com.google.cloud.android.dialogflow.ui.AudioIndicatorView.java
public AudioIndicatorView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setImageResource(R.drawable.ic_mic); mColorNormal = ContextCompat.getColor(context, R.color.input_button); mColorHearingVoice = ContextCompat.getColor(context, R.color.accent); ImageViewCompat.setImageTintList(this, ColorStateList.valueOf(mColorNormal)); }
From source file:org.telegram.ui.Cells.DrawerActionCell.java
public void setTextAndIcon(String text, int resId) { try {/*www . j a va2 s. c o m*/ textView.setText(text); Drawable dr = getContext().getDrawable(resId); if (dr != null) { DrawableCompat.setTintList(dr, ColorStateList.valueOf( ContextCompat.getColor(getContext(), R.color.secondary_text)) /*textView.getTextColors()*/); textView.setCompoundDrawablesWithIntrinsicBounds(dr, null, null, null); } } catch (Throwable e) { FileLog.e("tmessages", e); } }