4

I got a ListView where the background is black. Now my problem is that the default ripple effect is also black is the user cant really see it.

How can I change the color of the Ripple Effect without be dependent on API level ? (I want to achieve a white color).

4 Answers 4

3

You can set this as your views background:

<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="?android:attr/colorAccent">
<item android:id="@android:id/mask">
    <color android:color="#42ffffff" />
</item>

For more details see this question on stackoverflow:

What should be the color of the Ripple, colorPrimary or colorAccent? (Material Design)

And you can use this library for lower apis:

https://github.com/traex/RippleEffect

5
  • Is the <ripple tag not for Api 21 and up ? I have no compiler right now to test
    – Ahmet K
    Commented Mar 29, 2016 at 19:06
  • yes its for api 21+ and you can put this in drawable-v21 @AhmetKazaman
    – user6092941
    Commented Mar 30, 2016 at 7:59
  • Whats with all other apis lover than 21 ? I meant I need a solution for all
    – Ahmet K
    Commented Mar 30, 2016 at 12:41
  • for that you can use that library i mentioned in my edited answer @AhmetKazaman
    – user6092941
    Commented Mar 30, 2016 at 12:57
  • It does not give bound ripples
    – blackHawk
    Commented Mar 29, 2018 at 10:46
2

Simply way to do is define these two colors inside your colors.xml file

<color name="ripple_material_dark">#33ffffff</color>
<color name="ripple_material_light">#1f000000</color>

cheers.

1

Just add 'item: colorControlHighlight' with the desired color in your styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorControlHighlight">@color/white</item>
</style>
0

When using Theme.MaterialComponents.* theme the ripple color can be defined by adding following line to i.e. Ouline Button style.

<item name="rippleColor">@color/outline_button_ripple_color</item>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.