There are a ton of posts on the boards by people looking to add a simple background, gradient, border, rounded corner, etc to a View – often a TextView or ImageView. A lot of the answers involve overriding onDraw with a custom class, but a quick, simple alternative is to use a GradientDrawable.

Just create a new GradientDrawable with the color(s) you want, and use the setCornerRadii and setStroke methods to decorate (obviously optional).

Here’s an example that creates a partially transparent gradient with 5-dot rounded corners and a 1-dot black border:

This can be used anywhere, and is not required in onDraw.