/**
* Creates a new {@link RippleDrawable} introduced in Lollipop.
*
* @param normalColor Color for the idle/normal state
* @param rippleColor Color for the ripple effect
* @param bounds Clipping bounds for the ripple state. Set to {@code null} to get a borderless ripple
* @param cornerRadius Set to round the corners on rectangular drawables, 0 to disable
* @return A fully colored RippleDrawable, new instance each time
*/
@NonNull
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public static RippleDrawable createRippleDrawable(@ColorInt final int normalColor, @ColorInt final int rippleColor, @Nullable final Rect bounds,
@IntRange(from = 0) final int cornerRadius) {
Drawable maskDrawable = null;
if (bounds != null) {
// clip color is white
maskDrawable = createColoredDrawable(Color.WHITE, bounds);
if (maskDrawable instanceof GradientDrawable) {
((GradientDrawable) maskDrawable).setCornerRadius(cornerRadius);
}
maskDrawable.setBounds(bounds);
}
Drawable normalStateDrawable = null;
// transparent has no idle state
if (normalColor != Color.TRANSPARENT) {
normalStateDrawable = createColoredDrawable(normalColor, bounds);
if (normalStateDrawable instanceof GradientDrawable) {
((GradientDrawable) normalStateDrawable).setCornerRadius(cornerRadius);
}
}
return new RippleDrawable(ColorStateList.valueOf(rippleColor), normalStateDrawable, maskDrawable);
}
Coloring.java 文件源码
java
阅读 31
收藏 0
点赞 0
评论 0
项目:silly-android
作者:
评论列表
文章目录