I have a LinearLayout that I would like to change the background color of when one of its child views (an ImageButton) is clicked. I am able to do this, but not immediately
You might try forceLayout()
with a call to draw(canvas)
immediately after. If you did not override onLayout()
, onMeasure
, draw()
or onDraw()
, then the default implementation will run. The only issue with this is that you have to either get the Canvas or create one manually.
It is strongly discouraged to pursue this approach as Android is specifically designed to avoid drawing outside of normal updates. While you are correct that invalidate()
does not happen immediately, it is the safest and best way to encourage a redraw. If you want to handle drawing outside of updates, Android provides a way to do that with the SurfaceHolder class.