Please tell me how to reach both together, I have already considered many questions already asked, but they do not concern my problem.
I want to have a ripple effect on my button, as well as round it and have a background color. I must also be able to control the color of the ripple effect.
I tried a few things that are listed below.
First method: I tried to set style="@style/AppTheme"to a tag <Button>. This gives me a ripple effect and background color (using style <item name="colorButtonNormal">#500347</item>in style), but the button is not rounded.
To achieve a rounded shape, I gave android:background="@drawable/button_bg"in the tag <Button>. This makes the button rounded and the background color is achieved, but the ripple effect has disappeared.
Second method: I tried using a selector. 1. Created button_background.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:state_focused="true"
android:drawable="@drawable/button_bg"/>
<item
android:state_pressed="true"
android:drawable="@drawable/ripple_effect"/>
<item
android:drawable="@drawable/ripple_effect"/>
</selector>
rounded background for the button in button_bg.xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#500347" />
<corners
android:radius="10dip" />
<padding
android:bottom="0dip"
android:left="0dip"
android:right="0dip"
android:top="0dip" />
ripple_effet.xml:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:color="@android:color/holo_green_dark"
tools:targetApi="lollipop">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="@android:color/holo_green_dark" />
<corners android:radius="10dip" />
</shape>
- In tag
<Button>
android:background="@drawable/button_bg"
In this case, the method button is simply white when pressing returns to the background color.
Please tell me how to do this.
source
share