public class AppAnimateUtil {
public static void handleRippleBg(View rippleView, ColorStateList colorStateList, Context context, Drawable originalDrawable) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
RippleDrawable rippleDrawable = new RippleDrawable(colorStateList
, originalDrawable, new ColorDrawable(Color.parseColor("#DBE3EB")));
rippleView.setBackground(rippleDrawable);
} else {
TypedValue typedValue = new TypedValue();
context.getTheme().resolveAttribute(android.R.attr.selectableItemBackground, typedValue, true);
int[] attribute = new int[]{android.R.attr.selectableItemBackground};
TypedArray typedArray = context.getTheme().obtainStyledAttributes(typedValue.resourceId, attribute);
rippleView.setBackground(typedArray.getDrawable(0));
}
}
}
使用
private void initRipple() {
int color = Color.parseColor("#DBE3EB");
//设置ripple,5.0波纹效果
AppAnimateUtil.handleRippleBg(ivBack, ColorStateList.valueOf(color),
this, ivBack.getBackground());
AppAnimateUtil.handleRippleBg(mIvSave, ColorStateList.valueOf(color),
this, mIvSave.getBackground());
AppAnimateUtil.handleRippleBg(mIvCopy, ColorStateList.valueOf(color),
this, mIvCopy.getBackground());
}
网友评论