Can anyone please help me in understanding drawableStateChanged() method of toggle button in android?

StackOverflow https://stackoverflow.com/questions/20933094

  •  24-09-2022
  •  | 
  •  

Question

Can anyone please help me in understanding drawableStateChanged method of toggle button in android??? I wanted to know why exactly it is used for and how to implement it?? I found it on following link: http://developer.android.com/reference/android/widget/ToggleButton.html.

Was it helpful?

Solution

from reading through the documentation which states:

This function is called whenever the state of the view changes in 
such a way that it impacts the state of drawables being shown.

it seems that this function will be called by the framework whenever the component needs to be redrawn and you can override it to (for example) perform so application specific logic which you need to do when the component is redrawn, like manually drawing something over the top of the component, or changing the font or doing something which is not possible using the stock attributes.

This question has an example of how you might implement it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top