Task 4: Adding Color Resources

In this task you will learn how to create more resources like the string resources you’ve used earlier. With resources, you will be able to define values and use them across multiple parts throughout the app. In this case, color resources will be added to make changing the UI color scheme easier.

What you’ll learn:

Before we start, let’s go over how color is defined.

Color Definition:

Color Definition

(Don't worry about where this code is, we will get to that in a bit. )

Step 1: Using the color resources

We will first learn how to use the predefined color resources.

Color Resources

Within colors.xml, you should see that some color resources have already been defined.

(Note: Different Android Studio versions may have different colors than pictured.)

Predefined colors

Rerun the app and it should now look like this:

Rerun the app

Step 2: Creating new color resources

We will now create a custom color resource.

Create a new color resource
Pop up menu
Choose @color/screenBackground
Click on it
Custom color picker

Step 3: Exploring the width and height properties

Now that you know how to make color resources, we can now explore the width and height properties using them.

Layout section

Remember that you set the entire background to the screenBackground color:

ScreenBackground color
Wrap_content
Match_parent