Adding Theme Colors

With the base theme squared away, it is time to customize the attributes of BeatBox’s AppTheme.

In the styles.xml file, you will see three attributes. Update them to match Listing 21.7.

Listing 21.7  Setting theme attributes (res/values/styles.xml)

<style name="AppTheme" parent="Theme.AppCompat">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimaryred</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDarkdark_red</item>
    <item name="colorAccent">@color/colorAccentgray</item>
</style>

These theme attributes look similar to the style attributes that you set up earlier, but they specify different properties. Style attributes specify properties for an individual widget, such as the textStyle that you used to bold the button text. Theme attributes have a larger scope: They are properties that are set on the theme that any widget can access. For example, the app bar will look at the colorPrimary attribute on the theme to set its background color.

These three attributes have a large impact. The colorPrimary attribute is the primary color for your app’s brand. This color will be used as the app bar’s background and in a few other places.

colorPrimaryDark is used to color the status bar, which shows up at the top of the screen. Typically colorPrimaryDark will be a slightly darker version of your colorPrimary color. Status bar theming is a feature that was added to Android in Lollipop. Keep in mind that the status bar will be black on older devices (no matter what the theme specifies). Figure 21.5 shows the effect of these two theme attributes on BeatBox.

Figure 21.5  BeatBox with custom AppCompat color attributes

BeatBox with custom AppCompat color attributes

Finally, you set colorAccent to a gray color. colorAccent should contrast with your colorPrimary attribute; it is used to tint some widgets, such as an EditText.

You will not see the colorAccent attribute affect BeatBox, because Buttons do not support tinting. But you still specify colorAccent, because it is a good idea to think about these three color attributes together. These colors should mesh, and the default colorAccent attribute from your parent theme may clash with the other colors that you specified. This sets you up well for any future additions.

Run BeatBox to see the new colors. Your app should look like Figure 21.5.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.141.228