Custom XML Attributes For Your Custom Android Widgets

In the last part of my Custom UI Tutorial, commenter Knut asked:

Is there an easy way to declare the listener in XML (similar to the android:onClick=”onMyButtonClick” in the stock controls)?

This is a great question, and in answering his question, I’ll go ahead and show you how to create other custom attributes you can put in the XML for your custom widgets. The goal will be something like this in your layouts:

<com.kdion.tutorial.MyCustomWidget
	android:id="@+id/theId"
	<!-- ...more stuff here... -->
	custom:myText="Something"
	custom:fancyColors="true"
	custom:onAction="myDoSomething"
	/>

We have a custom View called MyCustomWidget, and along with the standard android: attributes, we have a few of our own: myText="Something", fancyColors="true", and onAction="doSomething". Presumably, these would map to attributes we already have for our custom widget which we could set in code, but we want a shortcut to set them from XML.
Continue reading Custom XML Attributes For Your Custom Android Widgets

Android Bitmap Blending – Color Channels

I recently was doing some investigation into doing image blending in android, and came across the quite powerful built-in capabilities of Paint. I was wondering if it was possible to combine several grayscale images into a color image, using the grayscale images as the color channels. If you are familiar with Photoshop or other graphics-editing programs, you are probably familiar with the concept of color channels, and how they are combined to create a color image. For this example, we will re-create the following image from its separated color channels:

The original, full color image
The original image. Original by Steve Berger Photography via flikr
Continue reading Android Bitmap Blending – Color Channels

Android UI Tutorial – Odometer Part III: Building the Odometer

[This is the third part of the tutortial so far. If you haven’t already, check out Part 1 and Part 2 to get up to speed on where we are. You can also grab the source code we ended up with at the end of Part 2 to follow along.]
Continue reading Android UI Tutorial – Odometer Part III: Building the Odometer

Android UI Tutorial – Odometer Part II: Completing the Spinner

[This is the second part in a three-part tutorial for creating an odometer widget in android. If you haven’t already, check out Part 1 to get up to speed on where we are. You can also grab the source code we ended up with at the end of Part 1 to follow along.]
Continue reading Android UI Tutorial – Odometer Part II: Completing the Spinner

Custom UI Elements in Android: Odometer Tutorial Part I

The finished Odometer

Introduction

This series of tutorials will provide an introduction to creating custom user interface elements in Android. By the end, you will have a complete custom widget that will allow input of numbers as if on an odometer. The user will slide the digits up and down, and change the digits.

This first part of the tutorial will get our test project created, and start building out the basic element of our odometer – a single-digit spinner.
Continue reading Custom UI Elements in Android: Odometer Tutorial Part I