Android Color Banding

Many Android programmers encounter severe color banding on devices like the Nexus One. For example, here is a radial gradient in an app I wrote this morning.

Banding on a Nexus One

There is an awful lot of misinformation out there, for example I see many people advocating dithering as a solution. Here is my app with dithering enabled:

Nexus One with Dithering

This is better, but won’t look so hot with many bitmaps. The correct solution is to take note of the format. As shown in the above images, Android’s default format is PixelFormat.OPAQUE. You can change this in a few ways. One way is to create a custom theme and set android:windowBackground to a color.

Another solution is to programmatically call Window.setFormat(PixelFormat.RGBA_8888).

The end result:

Eliminating Color Banding on the Nexus One

Sample code:

 public class MyActivity extends Activity {   @Override   public void onAttachedToWindow() {     super.onAttachedToWindow();     Window window = getWindow();     // Eliminates color banding     window.setFormat(PixelFormat.RGBA_8888);   } } 

Leave a Reply

Your email address will not be published. Required fields are marked *