Why does the ripple effect remove the original background?

So, I am trying to create a ripple effect with cusotm color and good success, in addition to the ripple effect, it removes the original background and thus creates the effect of a translucent ripple effect, which is not what I want.

Markup:

<Button android:layout_width="80dp" android:layout_height="80dp" android:text="Clicky" android:colorControlHighlight="@android:color/holo_blue_light" android:background="@drawable/selector"> </Button> 

hood / selector.xml:

 <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/ripple"/> <item android:drawable="@color/normal"/> </selector> 

extractor hood / ripple.xml:

 <?xml version="1.0" encoding="utf-8"?> <ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="#7f7"> </ripple> 

color.xml

 <resources> <color name="normal">#070</color> </resources> 

What do I need to do to keep the green (# 070) background while the ripple effect is applied? I believe this is an intention, right?

Edit

Now I have introduced shape , as suggested by AcademicDuck:

range hood / red_shape.xml:

 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@color/normal" /> </shape> 

This form refers to the now changed ripple:

extractor hood / ripple.xml:

 <?xml version="1.0" encoding="utf-8"?> <ripple xmlns:android="http://schemas.android.com/apk/res/android" android:drawaleb="@drawable/red_shape"> </ripple> 

Now the change is that when I click on the background, it's solid red instead of transparent. However, it does not pulsate.

+7
android material-design
source share
2 answers

To use your custom option, you need to specify it in a speaker like this ( RippleDrawable ):

 <ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/yourRippleColor"> <item android:drawable="@drawable/yourDrawable" /> </ripple> 

In addition, it is also worth checking the following questions: Android L Ripple Effect - Touch Feedback for buttons - using XML and an android ripple button with background

+1
source share

Android Ripple effects draw the top of the current background if no children are installed on the ripple tag. Inside the ripple tag, specify <item android:drawable = "@drawble/yourBackground"> . And make "yourBackground" a rectangular resource with the same background color as the button - # 070.

0
source share

All Articles