public static Drawable tintDrawable(Drawable drawable, ColorStateList cls, PorterDuff.Mode mode) {
if (drawable == null) return null;
Drawable wrapper = DrawableCompat.wrap(drawable.mutate());
DrawableCompat.setTintList(wrapper, cls);
DrawableCompat.setTintMode(drawable, mode);
return wrapper;
}
java类android.support.v4.graphics.drawable.DrawableCompat的实例源码
ThemeUtils.java 文件源码
项目:Mix
阅读 37
收藏 0
点赞 0
评论 0
ContextUtils.java 文件源码
项目:memetastic
阅读 21
收藏 0
点赞 0
评论 0
public Drawable tintDrawable(@Nullable Drawable drawable, @ColorInt int color) {
if (drawable != null) {
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable.mutate(), color);
}
return drawable;
}
NumberPadTimePickerBottomSheetComponent.java 文件源码
项目:NumberPadTimePicker
阅读 34
收藏 0
点赞 0
评论 0
@Override
public BottomSheetNumberPadTimePickerThemer setFabIconTint(ColorStateList tint) {
if (tint != null) {
int[] colors = extractColors(tint, STATES_FAB_COLORS);
if (mFabIconTintAnimator != null) {
mFabIconTintAnimator.setIntValues(colors);
} else {
mFabIconTintAnimator = createFabIconTintAnimator(colors);
}
}
DrawableCompat.setTintList(mOkButton.getDrawable(), tint);
return this;
}
AbstractDrawableUtils.java 文件源码
项目:tenor-android-demo-search
阅读 30
收藏 0
点赞 0
评论 0
/**
* Sets a tint on top of the desired drawable
*
* @param drawable source drawable to apply the tint
* @param tintColorInt color int of the desired tint
*/
public static void setDrawableTint(@NonNull final Drawable drawable,
@ColorInt final int tintColorInt) {
/*
* === FIXED ===
* In the latest support library, DrawableCompat.wrap() is no longer needed
*
* There is an invalidation issue when setting drawable state on pre-lollipop devices,
* even if using the DrawableCompat.setTint() method. It appears to be google support
* library issue. The get around is to use DrawableCompat.wrap() to wrap the drawable
* before setting tint color
*
* http://stackoverflow.com/questions/30872101
* https://code.google.com/p/android/issues/detail?id=172067#c13
* =============
*/
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
/*
* Tint ONLY the targeted drawable without affecting other drawables in the app.
*
* http://stackoverflow.com/questions/26788251
*/
Drawable mutateDrawable = drawable.mutate();
// Work for API 17 and below as well
mutateDrawable.setColorFilter(tintColorInt, PorterDuff.Mode.SRC_IN);
} else {
DrawableCompat.setTint(drawable, tintColorInt);
}
}
ThemeUtils.java 文件源码
项目:Xndroid
阅读 29
收藏 0
点赞 0
评论 0
@NonNull
private static Drawable getVectorDrawable(@NonNull Context context, int drawableId) {
Drawable drawable = ContextCompat.getDrawable(context, drawableId);
Preconditions.checkNonNull(drawable);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
drawable = (DrawableCompat.wrap(drawable)).mutate();
}
return drawable;
}
DialogAdapter.java 文件源码
项目:YCDialog
阅读 26
收藏 0
点赞 0
评论 0
private Drawable icon(Drawable drawable) {
if (drawable != null) {
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
@SuppressWarnings("SuspiciousNameCombination")
Drawable resizeIcon = new BitmapDrawable(context.getResources(), Bitmap.createScaledBitmap(bitmap, leftIcon, leftIcon, true));
Drawable.ConstantState state = resizeIcon.getConstantState();
resizeIcon = DrawableCompat.wrap(state == null ? resizeIcon : state.newDrawable().mutate());
return resizeIcon;
}
return null;
}
PresentationUtils.java 文件源码
项目:Melophile
阅读 14
收藏 0
点赞 0
评论 0
public static void setDrawableColor(TextView view, int color){
Drawable[] drawables=view.getCompoundDrawables();
for(Drawable drawable:drawables){
if(drawable!=null){
drawable.mutate();
DrawableCompat.setTint(drawable,color);
}
}
}
FloatingActionButtonImpl.java 文件源码
项目:cwac-crossport
阅读 27
收藏 0
点赞 0
评论 0
void setBackgroundDrawable(ColorStateList backgroundTint,
PorterDuff.Mode backgroundTintMode, int rippleColor, int borderWidth) {
// Now we need to tint the original background with the tint, using
// an InsetDrawable if we have a border width
mShapeDrawable = DrawableCompat.wrap(createShapeDrawable());
DrawableCompat.setTintList(mShapeDrawable, backgroundTint);
if (backgroundTintMode != null) {
DrawableCompat.setTintMode(mShapeDrawable, backgroundTintMode);
}
// Now we created a mask Drawable which will be used for touch feedback.
GradientDrawable touchFeedbackShape = createShapeDrawable();
// We'll now wrap that touch feedback mask drawable with a ColorStateList. We do not need
// to inset for any border here as LayerDrawable will nest the padding for us
mRippleDrawable = DrawableCompat.wrap(touchFeedbackShape);
DrawableCompat.setTintList(mRippleDrawable, createColorStateList(rippleColor));
final Drawable[] layers;
if (borderWidth > 0) {
mBorderDrawable = createBorderDrawable(borderWidth, backgroundTint);
layers = new Drawable[] {mBorderDrawable, mShapeDrawable, mRippleDrawable};
} else {
mBorderDrawable = null;
layers = new Drawable[] {mShapeDrawable, mRippleDrawable};
}
mContentBackground = new LayerDrawable(layers);
mShadowDrawable = new ShadowDrawableWrapper(
mView.getContext(),
mContentBackground,
mShadowViewDelegate.getRadius(),
mElevation,
mElevation + mPressedTranslationZ);
mShadowDrawable.setAddPaddingForCorners(false);
mShadowViewDelegate.setBackgroundDrawable(mShadowDrawable);
}
OneKeyClearEditText.java 文件源码
项目:Selector
阅读 16
收藏 0
点赞 0
评论 0
private void initClearDrawable(Context context) {
mClearDrawable = getCompoundDrawables()[2];// 获取EditText的DrawableRight,假如没有设置我们就使用默认的图片
if (mClearDrawable == null) {
// mClearDrawable = getResources().getDrawable(R.drawable.search_cancel, context.getTheme());
mClearDrawable = getResources().getDrawable(R.drawable.search_cancel);
}
DrawableCompat.setTint(mClearDrawable, DrawableColor);// 设置删除按钮的颜色和TextColor的颜色一致
mClearDrawable.setBounds(0, 0, (int) getTextSize(),
(int) getTextSize());// 设置Drawable的宽高和TextSize的大小一致
setClearIconVisible(false);
// 设置焦点改变的监听
setOnFocusChangeListener(this);
// 设置输入框里面内容发生改变的监听
addTextChangedListener(this);
}
DocumentView.java 文件源码
项目:Cable-Android
阅读 26
收藏 0
点赞 0
评论 0
public void setTint(int foregroundTint, int backgroundTint) {
DrawableCompat.setTint(this.document.getBackground(), backgroundTint);
DrawableCompat.setTint(this.documentBackground.getBackground(), foregroundTint);
this.document.setTextColor(foregroundTint);
this.fileName.setTextColor(foregroundTint);
this.fileSize.setTextColor(foregroundTint);
this.downloadButton.setColorFilter(foregroundTint);
this.downloadProgress.setBarColor(foregroundTint);
}