android Ripple effect 点击 水波效果 自定义背景颜色
来源:互联网 发布:域名top区别 编辑:程序博客网 时间:2024/05/24 13:28
自动转换的点击效果 设置一个normal颜色即可, 在5.0以上为 ripple, 在5.0一下表现为selector;
public class RippleDrawableUtils { /** * for general button with ripple above 5.0 and selector lower than. * * @param normalColorID id for normal color * @return backgroundDrawable */ public static Drawable getButtonRippleBackground( int normalColorID) { float radius = HSDisplayUtils.dip2px(2); int normalColor = HSApplication.getContext().getResources().getColor(normalColorID); getRippleColor(normalColor); return getCompatRippleDrawable(normalColor, getRippleColor(normalColor), radius); } public static Drawable getCompatRippleDrawable( int normalColor, int pressedColor, float radius) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return new RippleDrawable(getPressedColorSelector(normalColor, pressedColor), getShapeDrawable(normalColor, radius), getRippleMask(normalColor)); } else { return getStateListDrawable(normalColor, pressedColor, radius); } } private static int getRippleColor(int normalColor) { int r = (int) (((normalColor >> 16) & 0xFF) * 0.8); int g = (int) (((normalColor >> 8) & 0xFF) * 0.8); int b = (int) (((normalColor) & 0xFF) * 0.8); return Color.rgb(r, g, b); } private static ColorStateList getPressedColorSelector(int normalColor, int pressedColor) { return new ColorStateList( new int[][] { new int[]{android.R.attr.state_pressed}, new int[]{android.R.attr.state_focused}, new int[]{android.R.attr.state_activated}, new int[]{} }, new int[] { pressedColor, pressedColor, pressedColor, normalColor } ); } private static Drawable getRippleMask(int color) { float[] outerRadii = new float[8]; // 3 is radius of final ripple, // instead of 3 you can give required final radius Arrays.fill(outerRadii, 3); RoundRectShape r = new RoundRectShape(outerRadii, null, null); ShapeDrawable shapeDrawable = new ShapeDrawable(r); shapeDrawable.getPaint().setColor(color); return shapeDrawable; } private static StateListDrawable getStateListDrawable( int normalColor, int pressedColor, float radius) { StateListDrawable states = new StateListDrawable(); states.addState(new int[]{android.R.attr.state_pressed}, getShapeDrawable(pressedColor, radius)); states.addState(new int[]{android.R.attr.state_focused}, getShapeDrawable(pressedColor, radius)); states.addState(new int[]{android.R.attr.state_activated}, getShapeDrawable(pressedColor, radius)); states.addState(new int[]{}, getShapeDrawable(normalColor, radius)); return states; } private static GradientDrawable getShapeDrawable(int color, float radius) { GradientDrawable shape = new GradientDrawable(); shape.setCornerRadius(radius); shape.setColor(color); return shape; }
0 0
- android Ripple effect 点击 水波效果 自定义背景颜色
- Android 水波纹点击效果(Ripple Effect)
- Android 水波纹点击效果(Ripple Effect)
- Android 水波纹点击效果(Ripple Effect)
- Android 水波纹点击效果(Ripple Effect)
- Android 水波纹点击效果(Ripple Effect)
- Android 实现水波纹点击效果(Ripple Effect)
- (转)Android 水波纹点击效果(Ripple Effect)
- 【UI视觉】Android material Ripple 水波 点击效果
- android appcompat_v7 去掉点击效果或者自定义水波纹颜色
- 图像处理之水波纹扩散效果(water ripple effect)
- android 自定义水波纹点击效果Button
- android点击的ripple效果
- Android实现水波纹效果波纹效果(Ripple)
- Android 5.0 MaterialDesign Ripple效果水波纹效果
- Material Design风格的水波涟漪效果(Ripple Effect)的实现
- Android Ripple Effect
- 点击背景颜色效果
- jQuery parent>child
- LA 7454 Paranthesis
- CSS3 animation,@keyframes 动画
- Atmega128 + CH376串口方式问题记录
- Android实现通用的ActivityGroup(效果类似Android微博客户端主界面)
- android Ripple effect 点击 水波效果 自定义背景颜色
- 对于大流量的网站,您采用什么样的方法来解决访问量问题?
- 设计模式:抽象工厂模式
- 小程序之统计网页访问人数
- UCI
- Android多渠道打包方案的实践与优化
- html5
- spring注解注入:<context:component-scan>详解
- jemter 启动报错-解决办法