0

I'm wondering if we can animate the change in the isEnabled property of a view from true to false?

in more details, I have a view that when I want to change it's enabled property by calling setEnabled(false)

I want this change to be animated so that the transition of the enabled property from true to false takes a couple of milliseconds instead of being applied instantly.

is there a way to do this?

Mina Wissa
  • 10,923
  • 13
  • 90
  • 158
  • 1
    Animations are for where there can be partial states (e.g., animating the alpha from 0 to 1, animating the position from flush left to centered). What would a partially-enabled view be? If you want it to be delay a change, simply delay it using `postDelayed()` on the view to schedule the work to occur in the future. Also, bear in mind that Android's view system is locked into a 60fps cycle, so "a couple of milliseconds" is impractical in general. – CommonsWare Oct 24 '15 at 14:56
  • you're right, it's just I want the appearance of the view to change smoothly, I was wondering if that's possible. – Mina Wissa Oct 24 '15 at 14:58
  • 1
    If it is your own view, where you are rendering everything to the `Canvas` in your own code, you are welcome to somehow animate whatever your visual effect state change is when moving from enabled to disabled. If you are using existing widgets, where *they* are rendering to the `Canvas`, I know of no way to change how they render their visual effect state changes. – CommonsWare Oct 24 '15 at 15:01
  • 1
    As others have mentioned you need to animate some continuous value (e.g. opacity from 0 to 100 %). If we are talking about a button, one way to do what you want is to change the text color and background color. Here is an example: https://stackoverflow.com/a/66541862/753136 – tiktak Feb 15 '22 at 19:35

1 Answers1

0

As CommonsWare said, this can't be done this way.

Community
  • 1
  • 1
Mina Wissa
  • 10,923
  • 13
  • 90
  • 158