Skip to main content

Posts

Showing posts from July, 2019

Material ripple effect on Android Buttons

If you observe the buttons in recent apps, they all have ripple effect when you touch the buttons. How do you achieve it in your own app? Solution 1:  Change the foreground of the button to selectableItemBackground as shown below. <button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:foreground="?android:atrr/selectableItemBackground"        android:background="@color/buttonColor"  /> Works for : API 23 and above Solution 2:  Set the value for backgroundTint instead of changing the background. Works for : API 21 and above <button        android:layout_width="wrap_content"        android:layout_height="wrap_content”       android:backgroundTint="@color/buttonColor"  /> This gives ripple effect with the color specified. Solution 3: You can specify the ripple effect using xml and use this xml file as