The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.
We have already been exposed to
Theme.Material as part of this book, such as
with the action bar.
Android 5.0+, combined with
Theme.Material, gives you a lot of capabilities
tied to Google’s Material Design aesthetic. In this chapter, we will cover some
basic Material Design capabilities that will affect your
on Android 5.0+, starting with color.
Some developers want to change the colors used by their app to match some
specific color or color palette. In some cases, the colors in question are
tied to the app’s branding. In other cases, the developer simply wants something
different than the stock colors you get from something like
Creating custom themes to apply colors to
Theme.Holo and kin was enough
of a pain that a separate theme generator
was created for it, independent of the generator for custom action bar colors.
Affecting color changes in your
Theme.Material-based Android app is
vastly simplified — both for the action bar and the widgets — courtesy
Theme.Material’s tinting options.
In the chapter on the action bar, we saw how to set up
a custom theme based on
had custom color tinting rules that affected the action bar:
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="AppTheme" parent="android:Theme.Material"> <item name="android:colorPrimary">@color/primary</item> <item name="android:colorPrimaryDark">@color/primary_dark</item> <item name="android:colorAccent">@color/accent</item> </style> </resources>
At that time, we focused on the effects that these tints had on the
action bar itself. However, with
Theme.Material, not only do the tints
affect the action bar, but they affect the widgets themselves.
In some cases, the custom tints are not normally visible, such as with a button:
Figure 265: Custom Material Theme for a Button
However, when you tap the button, the animated “ripple” effect shown on the button will use your accent color.
In other cases, the accent color will show up in a more “steady state”,
such as in a checked
Figure 266: Custom Material Theme for a CheckBox
Similarly, your accent color shows up in things like:
Figure 267: Custom Material Theme for an EditText
Figure 268: Custom Material Theme for a RadioButton
Figure 269: Custom Material Theme for a Switch
Of course, you are welcome to pick whatever colors you like for your theme.
Google has its opinion of what it thinks are good ideas.
There is also the material palette site, which generates a color resource file based upon colors that you select from a large grid of color swatches.