Android is mainly a touch environment, but it has had rudimentary support for mice and keyboards for years. Mice will be getting more useful in Android N with the addition of a new mouse cursor API, which is available in its final form as of dev preview 4. The cursor can actually change to indicate actions just like on a desktop OS.

The custom pointer API allows developers to change the appearance, visibility, and behavior of the pointer. It can basically function more like a traditional cursor that changes depending on what you're doing. For example, when you hover over a text field it can become a text cursor. If you move to a link, you get the little hand. It also shows resize arrows when you point at a movable border. Developers can change this behavior in their apps using the API, which is now fully detailed on the dev site.

Google appears to have implemented this in a few places as part of the dev preview (see above), but it's not universal even in Google's apps yet. There were some custom cursors in previous previews, though it's somewhat more widespread now. Third-party devs will have to use the API if they want fancy custom cursors in Android N.

Custom Pointer API

Android N introduces the Custom Pointer API, which lets you customize the appearance, visibility, and behavior of the pointer. This capability is especially useful when a user is using a mouse or touchpad to interact with UI objects. The default pointer uses a standard icon. This API also includes advanced functionality such as changing the pointer icon's appearance based on specific mouse or touchpad movements.

To set a pointer icon, override the onResolvePointerIcon() method of the View class. This method uses a PointerIcon object to draw the icon that corresponds to a specific motion event.

  • Thanks:
  • Conor Ahern