This tutorial will help you to implement ripple effect on any type of view such as Button, TextView, and ImageView using material ripple. You can also customize ripple effect color. We can implement ripple effect from two ways.
1- Programmatically:- Suppose you want to implement ripple effect on TextView then you have to pass this view inside the method of MaterialRippleLayout class.
Example:
// Initialize TextView
TextView view = (TextView)findViewById(R.id.txt_ripple);
MaterialRippleLayout.on(view) // pass view in on() method
.rippleColor(Color.parseColor("#3F51B5")) // set color of ripple
.rippleAlpha(5f) // set alpha
.rippleHover(true) // enable ripple on hover view
.create(); // create ripple on view
[Click and drag to move]
2- Through XML file:- If we implement ripple effect on any view through XML then add view inside com.balysv.materialripple.MaterialRippleLayout element inside layout.
Example:
<com.balysv.materialripple.MaterialRippleLayout
android:layout_width="match_parent"
android:id="@+id/ripple_effect"
android:layout_height="wrap_content"
android:background="#ffff00"
android:layout_marginTop="24dp"
app:mrl_rippleOverlay="true"
app:mrl_rippleColor="#585858"
app:mrl_rippleAlpha="0.2"
app:mrl_rippleDelayClick="false"
app:mrl_rippleHover="true">-->
<Button
android:id="@+id/ripple_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Overlay with hover"/>
</com.balysv.materialripple.MaterialRippleLayout>
Add Supporting Library:- Add material ripple lib as a dependency in the build.gradle file.
dependencies {
compile 'com.balysv:material-ripple:1.0.2'
}
0 Comment(s)