I saw this kind of riplle effect in YouTube's android app. I want to get the same effect working in my app. Should I create an own Ripple-Drawable or is there a different approach?
Actually I already tried "?attr/selectableItemBackground" but the effect is much different.
Asked
Active
Viewed 90 times
-1

laim2003
- 299
- 4
- 19
-
This is handled by Material Design through AppCompat themes. Learn about those here: https://android-developers.googleblog.com/2014/10/appcompat-v21-material-design-for-pre.html – shkschneider Aug 22 '18 at 11:54
-
@shkschneider Thanks. I guess i already figured out my problem. – laim2003 Aug 22 '18 at 13:04
-
If so, please don't hesite to answer your own question and validate it ;) – shkschneider Aug 22 '18 at 13:08
-
1Try to use `android:background="?attr/selectableItemBackgroundBorderless"` – Prithvi Bhola Aug 22 '18 at 13:23
-
@shkschneider My answer will be online soon I hope. – laim2003 Aug 22 '18 at 13:37
2 Answers
0
You can create ripple from selector .See below example .
1.This is for API 21 and above, Create this in drawable
custom_ripple.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="@color/line" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@android:color/transparent" />
</shape>
</item>
</selector>
2.Add same name file in drawable-v21 for below 21 API.
v1/custom_ripple.xml
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/line">
<item
android:id="@android:id/mask"
android:drawable="@android:color/white" />
</ripple>
and finally set android:background="@drawable/custom_ripple" , where you want ripple.

Nisarg
- 172
- 6
0
Just add the value ?android:selectableItemBackgroundBorderless
to android:foreground
or android:background
Be sure to use the android namespace.

laim2003
- 299
- 4
- 19