Ripples on a shape with a transparent background

后端 未结 4 1697
情深已故
情深已故 2020-12-23 16:40

I am using the following shape in my app




        
4条回答
  •  星月不相逢
    2020-12-23 17:40

    You can have a ripple effect on transparent or semi-transparent background when the ripple mask is specified. The ripple mask is a Drawable but only the alpha value is used setting the ripple alpha per pixel. Here is an example for creating programmatically.

    var background = new android.graphics.drawable.GradientDrawable();
    background.setShape(android.graphics.drawable.GradientDrawable.RECTANGLE);
    background.setColor(0x77FFFFFF); // semi-transparent background
    background.setCornerRadius(10);
    background.setStroke(3, 0xFF1144FF); // border color
    
    var mask = new android.graphics.drawable.GradientDrawable();
    mask.setShape(android.graphics.drawable.GradientDrawable.RECTANGLE);
    mask.setColor(0xFF000000); // the color is irrelevant here, only the alpha
    mask.setCornerRadius(5); // you probably want the same corner as the background
    
    var rippleColorLst = android.content.res.ColorStateList.valueOf(
        android.graphics.Color.argb(255,50,150,255)
    );
    
    // aaaand
    var ripple = new android.graphics.drawable.RippleDrawable(rippleColorLst,background,mask);
    yourButton.setBackground(ripple);
    

    (Sorry for the JavaScript/NativeScript code, probably one can understand it)

提交回复
热议问题