Chapter 3. View tips and tricks
In this chapter, you’ll read about different hacks that use views. Most of them show how to customize and/or tweak widgets to perform certain functionalities.
We all know that validating data in forms is boring as well as error-prone. I worked on an Android application that used a lot of forms and had a couple of date inputs. I didn’t want to validate the date fields, so I found an elegant way to avoid it. The idea is to make users think they have an EditText when it’s in fact a button that will show a DatePicker when clicked.
To make this happen, we’ll change the default background of an Android Button to the EditText’s background. We can do this easily from the XML:
Note how we used @android:drawable instead of a drawable of our own. Using Android’s resources inside your application has its pros and cons. It makes your application fit in the device, but it’ll look different on different devices. Some developers prefer using their own resources, drawables, and themes to have their own look.