I need to do an animation for my button that changes its color from inside out without any flickering.It means the color should change from the center and the button should be stable.The button should not shrink or fade.The button color should change from the center point of button to the overall button.
Asked
Active
Viewed 2,898 times
-1
-
Are you looking for something like ripple effect just like we have for calculators etc in lolipop and marshmallow versions ? – Preetika Kaur Sep 16 '16 at 04:39
-
yes but to fill the button with another color from center of button to the entire button – Cool strom Sep 16 '16 at 06:14
-
Possible duplicate of [change button text color when pressed](http://stackoverflow.com/questions/9335279/change-button-text-color-when-pressed) – Soham Sep 16 '16 at 06:54
1 Answers
3
res/drawable/effect.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/colorPrimary"/>
<item android:state_pressed="true" android:drawable="@color/your_red_color" />
</selector>
Add effect.xml
as background of button:
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/effect"
android:text="Click Me" />

W4R10CK
- 5,502
- 2
- 19
- 30
-
Yes like this.I am new to android.Help me that when a button is pressed the button should change color from center of button to entire button.I don't even know how to use it. – Cool strom Sep 16 '16 at 06:12
-
what effect color do u want, in the button like the example I have given. – W4R10CK Sep 16 '16 at 06:14
-
button will be with blue before press and it should change to red .After released it should again be back to the blue color from entire button to center point(reverse) – Cool strom Sep 16 '16 at 06:17
-
this effect will not change the color of button, Its just a effect. If you want to change the color of button from blue to red it will be done. – W4R10CK Sep 16 '16 at 06:20
-
Ok how to use it please tell me how to do it.I am just statring android. – Cool strom Sep 16 '16 at 06:24
-
-
-
ohh sorry, I mean the `effect.xml` that u made in drawable file will be the background of button. – W4R10CK Sep 16 '16 at 08:54
-
I am asking for an animated color change but you are giving an normal color change – Cool strom Sep 19 '16 at 06:05
-
The question that u asked is too broad to answer here, although I would suggest to look here "http://trickyandroid.com/simple-ripple-reveal-elevation-tutorial/", accept answer if helped. – W4R10CK Sep 19 '16 at 06:08
-