Java Code Examples for android.graphics.drawable.Drawable#setTintMode()
The following examples show how to use
android.graphics.drawable.Drawable#setTintMode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProgressBar.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Should only be called if we've already verified that mProgressDrawable * and mProgressTintInfo are non-null. */ private void applyPrimaryProgressTint() { if (mProgressTintInfo.mHasProgressTint || mProgressTintInfo.mHasProgressTintMode) { final Drawable target = getTintTarget(R.id.progress, true); if (target != null) { if (mProgressTintInfo.mHasProgressTint) { target.setTintList(mProgressTintInfo.mProgressTintList); } if (mProgressTintInfo.mHasProgressTintMode) { target.setTintMode(mProgressTintInfo.mProgressTintMode); } // The drawable (or one of its children) may not have been // stateful before applying the tint, so let's try again. if (target.isStateful()) { target.setState(getDrawableState()); } } } }
Example 2
Source File: ProgressBar.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Should only be called if we've already verified that mProgressDrawable * and mProgressTintInfo are non-null. */ private void applyProgressBackgroundTint() { if (mProgressTintInfo.mHasProgressBackgroundTint || mProgressTintInfo.mHasProgressBackgroundTintMode) { final Drawable target = getTintTarget(R.id.background, false); if (target != null) { if (mProgressTintInfo.mHasProgressBackgroundTint) { target.setTintList(mProgressTintInfo.mProgressBackgroundTintList); } if (mProgressTintInfo.mHasProgressBackgroundTintMode) { target.setTintMode(mProgressTintInfo.mProgressBackgroundTintMode); } // The drawable (or one of its children) may not have been // stateful before applying the tint, so let's try again. if (target.isStateful()) { target.setState(getDrawableState()); } } } }
Example 3
Source File: ProgressBar.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Should only be called if we've already verified that mProgressDrawable * and mProgressTintInfo are non-null. */ private void applySecondaryProgressTint() { if (mProgressTintInfo.mHasSecondaryProgressTint || mProgressTintInfo.mHasSecondaryProgressTintMode) { final Drawable target = getTintTarget(R.id.secondaryProgress, false); if (target != null) { if (mProgressTintInfo.mHasSecondaryProgressTint) { target.setTintList(mProgressTintInfo.mSecondaryProgressTintList); } if (mProgressTintInfo.mHasSecondaryProgressTintMode) { target.setTintMode(mProgressTintInfo.mSecondaryProgressTintMode); } // The drawable (or one of its children) may not have been // stateful before applying the tint, so let's try again. if (target.isStateful()) { target.setState(getDrawableState()); } } } }
Example 4
Source File: BetterAdapter.java From auid2 with Apache License 2.0 | 6 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder viewHolder; if (convertView == null) { convertView = mLayoutInflater.inflate(R.layout.list_item, parent, false); viewHolder = new ViewHolder(convertView); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } ListItem listItem = getItem(position); Drawable drawable = mContext.getDrawable(R.drawable.person); drawable.setTintMode(PorterDuff.Mode.SRC_ATOP); drawable.setTint(listItem.getColor()); viewHolder.imageView.setImageDrawable(drawable); viewHolder.count.setText(listItem.getCount()); viewHolder.title.setText(listItem.getTitle()); viewHolder.subtitle.setText(listItem.getSubtitle()); return convertView; }
Example 5
Source File: Slider.java From appinventor-extensions with Apache License 2.0 | 5 votes |
private void setSliderColors() { if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { seekbar.setProgressTintList(ColorStateList.valueOf(leftColor)); if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP_MR1 || !(seekbar.getProgressDrawable() instanceof StateListDrawable)) { seekbar.setProgressBackgroundTintList(ColorStateList.valueOf(rightColor)); seekbar.setProgressBackgroundTintMode(Mode.MULTIPLY); } else { // Looking at the AOSP code, the previous calls should effectively accomplish what the // following code does... except it doesn't on Android 5.0. Instead, the result is that the // right side color is 50% opacity of leftColor. The following code works on Android 5.0, // but assumes a Drawable hierarchy that may not be true if the device manufacturer deviates // from the AOSP design. If that is the case, then the right hand side will not change. StateListDrawable drawable = (StateListDrawable) seekbar.getProgressDrawable(); if (drawable.getCurrent() instanceof LayerDrawable) { LayerDrawable layerDrawable = (LayerDrawable) drawable.getCurrent(); Drawable background = layerDrawable.findDrawableByLayerId(R.id.background); background.setTintList(ColorStateList.valueOf(rightColor)); background.setTintMode(Mode.MULTIPLY); } } } else { LayerDrawable fullBar = (LayerDrawable) seekbar.getProgressDrawable(); fullBar.setColorFilter(rightColor,PorterDuff.Mode.SRC); fullBar.findDrawableByLayerId(R.id.progress).setColorFilter(leftColor, PorterDuff.Mode.SRC); } }
Example 6
Source File: MorphButton.java From CanDialog with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void applyTint(Drawable d, TintInfo t) { if (d != null && t != null) { if (ResourcesCompat.LOLLIPOP) { if (t.mHasTintList || t.mHasTintMode) { d = d.mutate(); if (t.mHasTintList) { d.setTintList(t.mTintList); } if (t.mHasTintMode) { d.setTintMode(t.mTintMode); } } } else if (d instanceof Tintable) { // Our VectorDrawable and AnimatedVectorDrawable implementation if (t.mHasTintList || t.mHasTintMode) { d = d.mutate(); Tintable tintable = (Tintable) d; if (t.mHasTintList) { tintable.setTintList(t.mTintList); } if (t.mHasTintMode) { tintable.setTintMode(t.mTintMode); } } } else { //TODO: Should I attempt to make "stateful" ColorFilters from mBackgroundTint? if (t.mHasTintList) { int color = t.mTintList.getColorForState(getDrawableState(), Color.TRANSPARENT); setDrawableColorFilter(d, color, PorterDuff.Mode.SRC_IN); } } } }
Example 7
Source File: MaterialProgressBar.java From MaterialProgressBar with Apache License 2.0 | 5 votes |
@SuppressLint("NewApi") private void applyTintForDrawable(@NonNull Drawable drawable, @Nullable ColorStateList tint, boolean hasTint, @Nullable PorterDuff.Mode tintMode, boolean hasTintMode) { if (hasTint || hasTintMode) { if (hasTint) { if (drawable instanceof TintableDrawable) { //noinspection RedundantCast ((TintableDrawable) drawable).setTintList(tint); } else { logDrawableTintWarning(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { drawable.setTintList(tint); } } } if (hasTintMode) { if (drawable instanceof TintableDrawable) { //noinspection RedundantCast ((TintableDrawable) drawable).setTintMode(tintMode); } else { logDrawableTintWarning(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { drawable.setTintMode(tintMode); } } } // The drawable (or one of its children) may not have been // stateful before applying the tint, so let's try again. if (drawable.isStateful()) { drawable.setState(getDrawableState()); } } }
Example 8
Source File: LayerDrawable.java From Carbon with Apache License 2.0 | 5 votes |
@Override @TargetApi(Build.VERSION_CODES.LOLLIPOP) public void setTintMode(PorterDuff.Mode tintMode) { final ChildDrawable[] array = mLayerState.mChildren; final int N = mLayerState.mNum; for (int i = 0; i < N; i++) { final Drawable dr = array[i].mDrawable; if (dr != null) { dr.setTintMode(tintMode); } } }
Example 9
Source File: Carbon.java From Carbon with Apache License 2.0 | 5 votes |
public static void setTintListMode(Drawable drawable, ColorStateList tint, PorterDuff.Mode mode) { if (Carbon.IS_LOLLIPOP_OR_HIGHER) { drawable.setTintList(tint); drawable.setTintMode(mode); } else if (drawable instanceof TintAwareDrawable) { ((TintAwareDrawable) drawable).setTintList(tint); ((TintAwareDrawable) drawable).setTintMode(mode); } else { drawable.setColorFilter(tint == null ? null : new PorterDuffColorFilter(tint.getColorForState(drawable.getState(), tint.getDefaultColor()), mode)); } }
Example 10
Source File: FakeRingerActivity.java From fake-call-lollipop with BSD 2-Clause "Simplified" License | 4 votes |
private void setContactImage(boolean tint) { if (!(contactImageString == null)) { Uri contactImageUri = Uri.parse(contactImageString); try { InputStream contactImageStream = contentResolver.openInputStream(contactImageUri); Drawable contactImage = Drawable.createFromStream(contactImageStream, contactImageUri.toString()); if(tint) { contactImage.setTint(getResources().getColor(R.color.contact_photo_tint)); contactImage.setTintMode(PorterDuff.Mode.DARKEN); } contactPhoto.setImageDrawable(contactImage); } catch (Exception e) { } } }
Example 11
Source File: DrawableCompatL.java From adt-leanback-support with Apache License 2.0 | 4 votes |
public static void setTintMode(Drawable drawable, PorterDuff.Mode tintMode) { drawable.setTintMode(tintMode); }
Example 12
Source File: CanDialog.java From CanDialog with Apache License 2.0 | 3 votes |
/** * 设置svg图标颜色 * * @param d Drawable * @param color int */ @TargetApi(Build.VERSION_CODES.LOLLIPOP) private void applyTint(Drawable d, int color) { ColorStateList colorList = ColorStateList.valueOf(color); if (ResourcesCompat.LOLLIPOP) { d = d.mutate(); d.setTintList(colorList); d.setTintMode(PorterDuff.Mode.SRC_IN); } else if (d instanceof Tintable) { d = d.mutate(); Tintable tintable = (Tintable) d; tintable.setTintList(colorList); tintable.setTintMode(PorterDuff.Mode.SRC_IN); } else { int colorF = colorList.getColorForState(getDrawableState(), Color.TRANSPARENT); d.setColorFilter(colorF, PorterDuff.Mode.SRC_IN); } }