Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: can you have a ripple effect whose default state color is transparent?

Tags:

Something like the following, but it doesn't work. If I switch the drawable color to something like blue, it works.

<ripple xmlns:android="http://schemas.android.com/apk/res/android"     android:color="?android:colorControlHighlight">     <item android:drawable="@android:color/transparent"/> </ripple> 
like image 707
ZakTaccardi Avatar asked Feb 03 '15 21:02

ZakTaccardi


People also ask

What is ripple Android studio?

What is Ripple effect in Android? Ripple effect provides an instantaneous visual confirmation at the point of contact when users interact with UI elements. These UI elements could be any of the View elements. Like – Layouts, Buttons, TextViews, ListViews, etc.


2 Answers

It's necessary to add a mask:

<ripple xmlns:android="http://schemas.android.com/apk/res/android"     android:color="?android:colorControlHighlight">      <item android:id="@android:id/mask">        <color android:color="@android:color/white" />      </item> </ripple> 
like image 101
JMPergar Avatar answered Nov 07 '22 06:11

JMPergar


Somehow, the @JMPergar 's answer didn't work for me.

However, I was able to think of this workaround: if a colour behind your transparent button is solid (not a gradient or a speckled picture) - you can use that color as a main button's unpressed one.

<?xml version="1.0" encoding="utf-8"?> <ripple xmlns:android="http://schemas.android.com/apk/res/android"         android:color="@color/profile_transparent_button_pressed"         >      <item>         <shape>             <corners android:radius="@dimen/profile_transparent_button_corner_radius" />             <solid android:color="@color/profile_background" />         </shape>     </item> </ripple> 

where @color/profile_transparent_button_pressed is a colour to highlight a button, and @color/profile_background - the colour of a layout behind this button. It works exactly as expected, but still definitely is a workaround so you go try @JMPergar 's answer first.

like image 28
Den Drobiazko Avatar answered Nov 07 '22 05:11

Den Drobiazko