android tutorial - Rippledrawable in android | Developer android - android app development - android studio - android app developement
Ripple touch effect was introduced with material design in Android 5.0 (API level 21) and the animation is implemented by the new RippleDrawable class. Drawable that shows a ripple effect in response to state changes. The anchoring position of the ripple for a given state may be specified by calling setHotspot(float x, float y) with the corresponding state attribute identifier. 5.0 In general, ripple effect for regular buttons works by default in API 21 and above, and for other touchable views, it can be achieved by specifying:
android:background="?android:attr/selectableItemBackground"> for ripples contained within the view or: android:background="?android:attr/selectableItemBackgroundBorderless" for ripples that extend beyond the view's bounds. For example, in the image below, B1 is a button that does not have any background, B2 is set up with android:background="android:attr/selectableItemBackground" B3 is set up with android:background="android:attr/selectableItemBackgroundBorderless"
Learn - tutorial - learn android - android tutorial - android testing - mobile app developement - android code - android programming - android download - android examples - examples - programs
You can achieve the same in code using:
Ripples can also be added to a view using the android:foreground attribute the same way as above. As the name suggests, in case the ripple is added to the foreground, the ripple will show up above any view it is added to (e.g. ImageView, a LinearLayout containing multiple views, etc). If you want to customize the ripple effect into a view, you need to create a new XML file, inside the drawable directory. Here are few examples: Example 1: An unbounded ripple
If there is view with a background already specified with a shape, corners and any other tags, to add a ripple to that view use a mask layer and set the ripple as the backgro
Usage: To attach your ripple xml file to any view, set it as background as following (assuming your ripple file is named my_ripple.xml):
The ripple drawable can also be used in place of color state list selectors if your target version is v21 or above (you can also place the ripple selector in the drawable-v21 folder)
In this case, the color of the default state of your view would be white and the pressed state would show the ripple drawable.
Point to note: Using ?android:colorControlHighlight will give the ripple the same color as the built-in ripples in your app.
To change just the ripple color, you can customize the color android:colorControlHighlight in your theme like so:
Learn - tutorial - learn android - android tutorial - android testing - mobile app developement - android code - android programming - android download - android examples - examples - programs