0

I have a button that is clear with a white border, and when tapped it becomes light grey. My issue is this transition is instant and quite jarring to see. I want to learn how to smoothly flow from the one color to the other.

I have an XML file that has my button properties:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_pressed="true">
    <shape android:shape="rectangle">
        <corners android:radius="250px" />
        <padding android:left="100px" android:right="100px" />
        <stroke android:color="#cecece" android:width="15px" />
    </shape>
</item>

<item>
    <shape android:shape="rectangle">
        <corners android:radius="250px" />
        <padding android:left="100px" android:right="100px" />
        <stroke android:color="@color/colorWhite" android:width="15px" />
    </shape>
</item>

Then the activity's button has the XML file as the background.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • Try ripple effect or color state selector like examples in this Q:https://stackoverflow.com/questions/26686250/material-effect-on-button-with-background-color Or drawable selector like this https://stackoverflow.com/questions/7175873/click-effect-on-button-in-android – Mohamed Krayem Nov 12 '17 at 11:21

1 Answers1

0

You can use animated-selector instead of plain selector. And control the animation through alpha property.

Amit Kumar
  • 391
  • 3
  • 10