How to set ripple effect on textview or image on Android?

I want to set ripple effect on textview and imageview in Android Studio. How can i do this?

+56
android android-textview android-imageview material-design
Nov 02 '15 at 11:54 on
source share
8 answers

Link: http://developer.android.com/training/material/animations.html ,

http://wiki.workassis.com/category/android/android-xml/

<TextView . . android:background="?attr/selectableItemBackgroundBorderless" android:clickable="true" /> <ImageView . . . android:background="?attr/selectableItemBackgroundBorderless" android:clickable="true" /> 
+156
Dec 07 '15 at 8:09
source share

If you want ripples to be limited by the size of the TextView / ImageView, use:

 <TextView android:background="?attr/selectableItemBackground" android:clickable="true"/> 

(I think he looks better)

+40
May 6 '16 at 1:08 a.m.
source share

You can use android-ripple-background

Start effect

 final RippleBackground rippleBackground=(RippleBackground)findViewById(R.id.content); ImageView imageView=(ImageView)findViewById(R.id.centerImage); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { rippleBackground.startRippleAnimation(); } }); 

Stop animation:

 rippleBackground.stopRippleAnimation(); 
+5
Nov 02 '15 at 11:57
source share
 <TextView android:id="@+id/txt_banner" android:layout_width="match_parent" android:text="@string/banner" android:gravity="center|left" android:layout_below="@+id/title" android:background="@drawable/ripple_effect" android:paddingLeft="15dp" android:textSize="15sp" android:layout_height="45dp" /> 

add this to readable

 <?xml version="1.0" encoding="utf-8"?> <!--this ribble animation only working for >= android version 21--> <ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/click_efect" /> 

try it.

+3
Sep 15 '16 at 10:51
source share

Or you can try using this library (android 9+): RippleEffect

Integration

 dependencies { compile 'com.github.traex.rippleeffect:library:1.3' } 

Application:

 <com.andexert.library.RippleView android:id="@+id/more" android:layout_width="?android:actionBarSize" android:layout_height="?android:actionBarSize" android:layout_toLeftOf="@+id/more2" android:layout_margin="5dp" rv_centered="true"> <ImageView android:layout_width="?android:actionBarSize" android:layout_height="?android:actionBarSize" android:src="@android:drawable/ic_menu_edit" android:layout_centerInParent="true" android:padding="10dp" android:background="@android:color/holo_blue_dark"/> </com.andexert.library.RippleView> 
+1
Nov 02 '15 at 12:01
source share

The best way is to use libraries. This is one of them. Just add its dependency and put the below code in xml in front of each element that needs a ripple effect:

 <com.balysv.materialripple.MaterialRippleLayout android:id="@+id/ripple" android:layout_width="match_parent" android:layout_height="wrap_content"> 
+1
Nov 02 '15 at 19:58
source share

In addition to @Bikesh M Annur, answer, be sure to update your support libraries. I used to use 23.1.1, and nothing happened. Updating it to 23.3.0 did the trick.

+1
Jul 26 '16 at 6:56
source share

In the case of a well-voted solution sent by @Bikesh M Annur ( here ) does not suit you, try using:

 <TextView ... android:background="?android:attr/selectableItemBackgroundBorderless" android:clickable="true" /> <ImageView ... android:background="?android:attr/selectableItemBackgroundBorderless" android:clickable="true" /> 

Also, when using android:clickable="true" add android:focusable="true" because:

"A widget declared clickable but not declared for focus is not accessible from the keyboard."

0
Dec 07 '17 at 19:20
source share



All Articles