Reputation: 61
I'm making a note app. I started with design, so I don't have any code yet. I made a button with an image of a "+" and a gradient background, but ended up losing the ripple effect. I saw some with similar problems, but I didn't understand anything. How do I recover the ripple effect? Currently, it only works on the image, but I want it on the entire button, including the background.
add_button_design.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<item>
<shape>
<gradient android:startColor="#706fd3" android:endColor="#34ace0" android:angle="45"/>
<corners android:radius="50dp"/>
<stroke android:width="1px" android:color="#227093"/>
</shape>
</item>
<item>
<bitmap android:src="@drawable/add_button_image"/>
</item>
<item>
<ripple android:color="?android:attr/colorControlHighlight">
<item android:drawable="@drawable/add_button_image"/>
</ripple>
</item>
</layer-list>
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" android:background="@color/colorPrimaryDark">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_margin="20dp"
android:background="@drawable/add_button_design"/>
</RelativeLayout>
</FrameLayout>
</RelativeLayout>
I know this can be considered a duplicate question, but the others don't fit my plans.
Upvotes: 0
Views: 363
Reputation: 61
using the @Leon base, I managed to fix it. Just put everything inside the Ripple Tag
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<item>
<ripple android:color="?android:attr/colorControlHighlight">
<item>
<shape>
<gradient android:startColor="#706fd3" android:endColor="#34ace0" android:angle="45"/>
<corners android:radius="50dp"/>
<stroke android:width="1px" android:color="#227093"/>
</shape>
</item>
<item>
<bitmap android:src="@drawable/add_button_image"/>
</item>
</ripple>
</item>
</layer-list>
Upvotes: 0
Reputation: 9234
Please add the selector
in your ripple
tag. Here is running GIF.
Here is code.
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<item>
<shape>
<gradient android:startColor="#706fd3" android:endColor="#34ace0" android:angle="45"/>
<corners android:radius="50dp"/>
<stroke android:width="1px" android:color="#227093"/>
</shape>
</item>
<item>
<bitmap android:src="@drawable/add_button_image"/>
</item>
<item>
<ripple android:color="?android:attr/colorControlHighlight">
<!--<item android:drawable="@drawable/add_button_image"/>-->
<selector>
<!-- unclick the background-->
<item
android:drawable="@drawable/add_button_image"
android:state_pressed="false" />
<!-- click the background-->
<item
android:drawable="@drawable/add_button_image"
android:state_pressed="true" />
</selector>
</ripple>
</item>
</layer-list>
Upvotes: 1