美文网首页
一个关于安卓点击水波纹效果的工具类

一个关于安卓点击水波纹效果的工具类

作者: Tyson_Wu | 来源:发表于2023-10-23 09:43 被阅读0次
    
    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());
        }
    

    相关文章

      网友评论

          本文标题:一个关于安卓点击水波纹效果的工具类

          本文链接:https://www.haomeiwen.com/subject/ucadidtx.html