List of usage examples for android.support.v4.graphics.drawable DrawableCompat setTintList
public static void setTintList(Drawable drawable, ColorStateList colorStateList)
From source file:com.nadmm.airports.utils.UiUtils.java
static public Drawable getTintedDrawable(Context context, int resid, ColorStateList tintList) { // Get a mutable copy of the drawable so each can be set to a different color String key = String.format(Locale.US, "%d:%d", resid, tintList.getDefaultColor()); Drawable d = getDrawableFromCache(key); if (d == null) { d = ResourcesCompat.getDrawable(context.getResources(), resid, null).mutate(); DrawableCompat.setTintList(d, tintList); putDrawableIntoCache(key, d);//from ww w . j a va 2 s. c o m } return d; }
From source file:com.fa.mastodon.fragment.ComposeOptionsFragment.java
private static void setRadioButtonDrawable(Context context, RadioButton button, @DrawableRes int id) { ColorStateList list = new ColorStateList( new int[][] { new int[] { -android.R.attr.state_checked }, new int[] { android.R.attr.state_checked } }, new int[] { ThemeUtils.getColor(context, R.attr.compose_image_button_tint), ThemeUtils.getColor(context, R.attr.colorAccent) }); Drawable drawable = VectorDrawableCompat.create(context.getResources(), id, context.getTheme()); if (drawable == null) { return;/*from w ww . ja va 2s. co m*/ } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { button.setButtonTintList(list); } else { drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTintList(drawable, list); } button.setButtonDrawable(drawable); }
From source file:com.facebook.react.views.slider.ReactSlider.java
@TargetApi(21) public void setProgressBackgroundColor(Integer value) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setProgressBackgroundTintList(ColorStateList.valueOf(value)); } else {/*from ww w. jav a2 s . c o m*/ if (getProgressDrawable() instanceof LayerDrawable) { LayerDrawable layer = (LayerDrawable) getProgressDrawable(); DrawableCompat.setTintList(layer.findDrawableByLayerId(android.R.id.background).mutate(), ColorStateList.valueOf(value)); } } }
From source file:com.appdevper.mediaplayer.adater.MediaItemViewHolder.java
static View setupView(Activity activity, View convertView, ViewGroup parent, MediaMetadataCompat item, int state) { if (sColorStateNotPlaying == null || sColorStatePlaying == null) { initializeColorStateLists(activity); }/* w w w . j a va 2s .c om*/ MediaItemViewHolder holder; Integer cachedState = STATE_INVALID; if (convertView == null) { convertView = LayoutInflater.from(activity).inflate(R.layout.media_list_item, parent, false); holder = new MediaItemViewHolder(); holder.mImageView = (ImageView) convertView.findViewById(R.id.play_eq); holder.mTitleView = (TextView) convertView.findViewById(R.id.title); holder.mDescriptionView = (TextView) convertView.findViewById(R.id.description); convertView.setTag(holder); } else { holder = (MediaItemViewHolder) convertView.getTag(); cachedState = (Integer) convertView.getTag(R.id.tag_mediaitem_state_cache); } holder.mTitleView.setText(item.getString(MediaMetadataCompat.METADATA_KEY_TITLE)); holder.mDescriptionView.setText(item.getString(MediaMetadataCompat.METADATA_KEY_ALBUM)); // If the state of convertView is different, we need to adapt the view to the // new state. if (cachedState == null || cachedState != state) { switch (state) { case STATE_PLAYABLE: Drawable pauseDrawable = ContextCompat.getDrawable(activity, R.drawable.ic_play_arrow_black_36dp); DrawableCompat.setTintList(pauseDrawable, sColorStateNotPlaying); holder.mImageView.setImageDrawable(pauseDrawable); holder.mImageView.setVisibility(View.VISIBLE); break; case STATE_PLAYING: AnimationDrawable animation = (AnimationDrawable) ContextCompat.getDrawable(activity, R.drawable.ic_equalizer_white_36dp); DrawableCompat.setTintList(animation, sColorStatePlaying); holder.mImageView.setImageDrawable(animation); holder.mImageView.setVisibility(View.VISIBLE); animation.start(); break; case STATE_PAUSED: Drawable playDrawable = ContextCompat.getDrawable(activity, R.drawable.ic_equalizer1_white_36dp); DrawableCompat.setTintList(playDrawable, sColorStatePlaying); holder.mImageView.setImageDrawable(playDrawable); holder.mImageView.setVisibility(View.VISIBLE); break; default: holder.mImageView.setVisibility(View.GONE); } convertView.setTag(R.id.tag_mediaitem_state_cache, state); } return convertView; }
From source file:com.commonsware.cwac.crossport.design.widget.FloatingActionButtonImpl.java
void setBackgroundTintList(ColorStateList tint) { if (mShapeDrawable != null) { DrawableCompat.setTintList(mShapeDrawable, tint); }//from w ww . j ava2s . c o m if (mBorderDrawable != null) { mBorderDrawable.setBorderTint(tint); } }
From source file:com.wanderingcan.persistentsearch.SearchMenuItem.java
public SearchMenuItem setIconTintList(@Nullable ColorStateList tint) { mIconTint = tint; DrawableCompat.setTintList(mIconDrawable, tint); notifyItemChanged(); return this; }
From source file:com.wanderingcan.persistentsearch.SearchMenuItem.java
public SearchMenuItem setActionIconTint(@Nullable ColorStateList tint) { mActionTint = tint;// w w w .j a va2 s. c o m DrawableCompat.setTintList(mActionDrawable, tint); notifyItemChanged(); return this; }
From source file:com.landenlabs.all_UiDemo.frag.ImageScalesFrag.java
private void setScaledVector(ImageView imageView, int imageRes) { Drawable rawDrawable;// w ww.j a v a2 s.com if (Build.VERSION.SDK_INT >= 21) { rawDrawable = getResources().getDrawable(imageRes, getTheme()); } else { rawDrawable = getResources().getDrawable(imageRes); } Drawable drawable = rawDrawable.mutate(); /* int pad = 50; drawable.setBounds(0, pad, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); */ // ScaleDrawable does nothing !!!! if (false) { ScaleDrawable scaleDrawable = new ScaleDrawable(rawDrawable, Gravity.TOP | Gravity.LEFT, 2.0f, 0.8f); scaleDrawable.setLevel(8000); drawable = scaleDrawable.getDrawable(); } if (false) { int tintColor = 0x80ff0000; ColorStateList colorStateList = new ColorStateList(new int[][] { new int[] {} }, new int[] { tintColor }); drawable = DrawableCompat.wrap(drawable.mutate()); DrawableCompat.setTintList(drawable, colorStateList); DrawableCompat.setTintMode(drawable, PorterDuff.Mode.MULTIPLY); } //imageView.setScaleType(ImageView.ScaleType.CENTER); imageView.setImageDrawable(drawable); // imageView.setImageDrawable(null); // imageView.setBackgroundDrawable(drawable); }
From source file:com.facebook.react.views.slider.ReactSlider.java
@TargetApi(21) public void setThumbColor(Integer value) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setThumbTintList(ColorStateList.valueOf(value)); } else {/*from w w w . j a va2s .c o m*/ DrawableCompat.setTintList(getThumb().mutate(), ColorStateList.valueOf(value)); } }
From source file:com.commonsware.cwac.crossport.design.widget.FloatingActionButtonImpl.java
void setRippleColor(int rippleColor) { if (mRippleDrawable != null) { DrawableCompat.setTintList(mRippleDrawable, createColorStateList(rippleColor)); } }