Monday, September 7, 2015

Create a Compound Widget for Android Lollipop: Part 1

This is the first in a four part article detailing the implementation of a compound widget for Android Lollipop. A compound widget is a widget that is made up of other preexisting widgets. Typically a compound widget will hide the properties those sub widgets usually expose and expose its own custom properties instead.

The example I am going to use is to recreate the classic color picker control. The first version of this I remember seeing was on the Commodore Amiga 30 years ago.


I am going to create a simplified version of this that will set one color.


The Plan

I am going to follow these steps to create my compound widget:

Part 2. Create a layout for my compound widget.
Part 3. Create a class for my compound widget.
Part 4. Integrate my compound widget with other code.

Create a test project

 I am going to start by creating a new project in Android Studio which I'm going to call Color Picker Example.



I will set the minimum SDK to API 21 which is the first version of Lollipop. Android Studio shows the percentage of active Android devices that are compatible with the selected SDK. I could increase the percentage by picking an older SDK. However that would cause the app to be created to use the compatibility library which does not implement all of the features of the widgets that I want to use.



I am going to create the test project with a blank activity which I will add my widget to later. The 'blank' activity is not really blank as it is created with  a 'Hello world' TextView widget.


I will accept the defaults on the 'Customize the Activity' page and click finish. Android Studio opens the new project and displays the layout editor for the main activity.


This concludes this part of the article. You can read the other parts here:


No comments:

Post a Comment