2

Hi i have a button with an enabled state and disabled state.initially it will be in disabled state as shown below

Disabled State

At a particular time i need to enable it as shown below

Enabled State

I want to animate this state change

This is my Invalid Drawable :-

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@android:color/transparent" />
    <corners android:radius="2dp" />
    <stroke
        android:width="1dp"
        android:color="#FFFFFF" />
</shape>

And below is my Enabled State :-

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#FFFFFF" />
    <corners android:radius="2dp" />
    <stroke
        android:width="1px"
        android:color="#FFFFFF" />
</shape>

how can i animate this state change on an event trigger??

Jongware
  • 22,200
  • 8
  • 54
  • 100
Nidhin Prathap
  • 696
  • 5
  • 15
  • Possible duplicate of [Animate selector/state transitions](http://stackoverflow.com/questions/9221535/animate-selector-state-transitions) – Bö macht Blau Mar 21 '16 at 18:09
  • @0X0nosugar i need to have this on text change or some validation... – Nidhin Prathap Mar 21 '16 at 18:14
  • 1
    I thought the first answer might be what you're looking for: *TransitionDrawables*. They can be started programmatically: transition.startTransition(transitionTime); But maybe the link-to-another-answer in that first answer is even more helpful. – Bö macht Blau Mar 21 '16 at 18:26
  • @0X0nosugar im able to achieve the result using TransitionDrawable as metioned... have pasted the code below.. thanx – Nidhin Prathap Mar 21 '16 at 18:29

1 Answers1

2

Was able to achieve the result using TransitionDrawable

final Handler handler = new Handler();

        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                TransitionDrawable transition = (TransitionDrawable) btnSignIn.getBackground();
                transition.startTransition(1000);
                btnSignIn.setTextColor(Color.BLACK);
            }
        }, 1000);

and my new drawable is like :-

<?xml version="1.0" encoding="utf-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- The drawables used here can be solid colors, gradients, shapes, images, etc. -->
    <item android:drawable="@drawable/invalid_button" />
    <item android:drawable="@drawable/valid_button" />
</transition>

Where invalid_button.xml :

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@android:color/transparent" />
    <corners android:radius="2dp" />
    <stroke
        android:width="1dp"
        android:color="#FFFFFF" />
</shape>

And valid_button.xml :

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#FFFFFF" />
    <corners android:radius="2dp" />
    <stroke
        android:width="1px"
        android:color="#FFFFFF" />
</shape>
Nidhin Prathap
  • 696
  • 5
  • 15