B4A Library RippleDrawable

This library allows to create RippleDrawables (drawables that show a ripple effect in response to state changes) for API >= 21 with custom colors. You can assign these drawables to the background of any view.

In the following example, a RippleDrawable or a StateListDrawable is used depending on the Android version, so this code can be run on any device:
B4X:
Dim btn As Button
btn.Initialize("btn")
Dim P As Phone
If P.SdkVersion < 21 Then
     'Android version < 5.0 Lollipop -> StateListDrawable
     Dim PressedCD As ColorDrawable
     PressedCD.Initialize(Colors.Blue, 0)
     Dim DefaultCD As ColorDrawable
     DefaultCD.Initialize(Colors.Gray, 0)
     Dim bStateList As StateListDrawable
     bStateList.Initialize
     bStateList.AddState(bStateList.State_Pressed, PressedCD)
     bStateList.AddCatchAllState(DefaultCD)
     btn.Background = bStateList
Else
     'Android version >= 5.0 Lollipop -> RippleDrawable
     Dim bRipple As RippleDrawable
     bRipple.Initialize(Colors.Gray, Colors.Blue)
     btn.Background = bRipple.Drawable
End If
btn.TextColor = Colors.White
btn.Text = "Styled button"
Activity.AddView(btn, 0, 0, 50%x, 10%y)
 

Attachments

  • RippleDrawable + source v1.1.zip
    4.7 KB · Views: 415
Last edited:
Top