/**
* Creates a new drawable (implementation of the Drawable object may vary depending on the OS version).
* The result Drawable will be colored with the given color, and clipped to match the given bounds.
* Note that the drawable's alpha is set to 0 when argument color is {@link Color#TRANSPARENT}.
*
* @param color Integer color used to color the output drawable
* @param bounds Four-dimensional vector representing drawable bounds
* @return Colored and clipped drawable object
*/
@NonNull
public static Drawable createColoredDrawable(@ColorInt final int color, @Nullable final Rect bounds) {
// create the drawable depending on the OS (pre-Honeycomb couldn't use color drawables inside state lists)
Drawable drawable;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB || bounds != null) {
drawable = new GradientDrawable(Orientation.BOTTOM_TOP, new int[] { color, color }).mutate();
} else {
drawable = new ColorDrawable(color).mutate();
}
// set the alpha value
if (color == Color.TRANSPARENT) {
drawable.setAlpha(0);
}
// update bounds
if (bounds != null) {
drawable.setBounds(bounds);
}
return drawable;
}
Coloring.java 文件源码
java
阅读 49
收藏 0
点赞 0
评论 0
项目:silly-android
作者:
评论列表
文章目录