Is there a way to change the button visual when using button:setEnabled(false) ?

Hi,

I’d like to be able to disable a button, but have the visual display the button like it does when the button is being pushed. This will indicate to the user that it is not available to press. 

Currently, using button:setEnabled(false) just turns off the event listener for touch events and doesn’t actually change how the button looks.

Hi @spacewolf,

I haven’t tested this, but you may be able to dispatch a “fake touch” (began phase) to the button using object:dispatchEvent(). At the same time, disable the button using :setEnabled so that the user can’t manipulate it. Again, I haven’t tested this, but in theory it should work.

http://docs.coronalabs.com/api/type/EventListener/dispatchEvent.html

Brent

Thanks for your reply Brent. I didn’t end up using your solution because I figured the following code ended up being easier for a button “looking” disabled instead of using the actual pressed state:

button:setFillColor( .4, .4, .4, .3 ) button:setEnabled( false )

Much easier! I guess I was over-complicating what is actually a simple solution (yours). :slight_smile:

Hi @spacewolf,

I haven’t tested this, but you may be able to dispatch a “fake touch” (began phase) to the button using object:dispatchEvent(). At the same time, disable the button using :setEnabled so that the user can’t manipulate it. Again, I haven’t tested this, but in theory it should work.

http://docs.coronalabs.com/api/type/EventListener/dispatchEvent.html

Brent

Thanks for your reply Brent. I didn’t end up using your solution because I figured the following code ended up being easier for a button “looking” disabled instead of using the actual pressed state:

button:setFillColor( .4, .4, .4, .3 ) button:setEnabled( false )

Much easier! I guess I was over-complicating what is actually a simple solution (yours). :slight_smile: