/
DrawableLess.java
39 lines (30 loc) · 1.36 KB
/
DrawableLess.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.jayfeng.lesscode.core;
import android.content.res.ColorStateList;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.support.v4.graphics.drawable.DrawableCompat;
public final class DrawableLess {
/**
* ========================================================
* tint drawable with Color or ColorStateList
* using the DrawableCompat in support v4 library
* ========================================================
*/
public static Drawable $tint(Drawable originDrawable, int color) {
return $tint(originDrawable, ColorStateList.valueOf(color));
}
public static Drawable $tint(Drawable originDrawable, int color, PorterDuff.Mode tintMode) {
return $tint(originDrawable, ColorStateList.valueOf(color), tintMode);
}
public static Drawable $tint(Drawable originDrawable, ColorStateList colorStateList) {
return $tint(originDrawable, colorStateList, null);
}
public static Drawable $tint(Drawable originDrawable, ColorStateList colorStateList, PorterDuff.Mode tintMode) {
Drawable tintDrawable = DrawableCompat.wrap(originDrawable);
if (tintMode != null) {
DrawableCompat.setTintMode(tintDrawable, tintMode);
}
DrawableCompat.setTintList(tintDrawable, colorStateList);
return tintDrawable;
}
}