Enabling Input

If you set the SurfaceView to be on top from a Z axis standpoint, then input events delivered to the SurfaceView will be routed to the corresponding widgets and their listeners.

In these examples, ViewService added an OnClickListener to the Button. If you click the Button as viewed in EmbedClient, you see the button caption being updated by that listener. You also see the standard ripple effect, though fine-grained animations like that do not seem to work well, even on relatively good hardware (e.g., a Pixel 2).

The trick to making this work is setting that Z axis order, which we do in the EmbedClient edition of MainActivity via setZOrderOnTop(true):

    binding.surface.setZOrderOnTop(true)

Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.