Stackoverflow has a bunch of examples of how to apply a ColorFilter (and therefore a ColorMatrix) to a bitmap, or an ImageView (which has a built-in API), but applying color effects to an entire View are not nearly as well documented.

The basic idea is to use your ColorMatrix instances in ColorFilters, then wrap that in a ColorMatrixColorFilter. Then apply that to a Paint instance. That’s all pretty well documented, but what happens after that is less so.

One approach is to use dispatchDraw or onDraw:

But in looking at the docs, we can see several warnings about performance around this approach – in fact more than doubling the work:

The short answer is to apply the paint via setLayerType – the source recommends a hardware layer but IME either will work:

Here’s an example of subclass of Paint that can be inverted, and accepts a range of contrast values. You can share this paint among any number of Views using setLayerType. Caveat: invalidating does not seem to update the View as normal, and in some cases I’ve had to call setLayerType again after changes to the Paint’s values.