O'Reilly logo

Building Android UIs with Custom Views by Raimon Ràfols Montané

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Bitmaps

Let's start by drawing bitmaps or images. Instead of having a white background, we'll use an image as background for our custom view. Using the source code from our previous example, we could do some very simple modifications to draw an image:

First, let's define a Bitmap object that will hold a reference to the image:

private Bitmap backgroundBitmap; 

To start, let's initialize it with the application icon we already have on our application:

 

public CircularActivityIndicator(Context context, AttributeSet attributeSet) { 
    super(context, attributeSet); 
     
    backgroundBitmap = BitmapFactory.decodeResource(getResources(),    R.mipmap.ic_launcher); 

BitmapFactory provides us several ways to load and decode images.

Once we have the image loaded, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required