This app displays correct answers in green and incorrect answers in red. As with any other resource, color resources should be defined in XML so that you can easily change colors without modifying your app’s Java source code. Typically, colors are defined in a file name colors.xml
, which you must create. As you learned in Section 3.4.5, colors are defined using the RGB or ARGB color schemes.
To create the file and configure the two color resources, perform the following steps:
1. In the project’s res
folder, right click the values
folder, then select New > Android XML File to display the New Android XML File dialog.
2. Specify colors.xml
in the File field and click Finish to create the file.
3. If the IDE opens the new file in XML view, click the Resources tab at the bottom of the window to view the resource editor.
4. To create a color resource, click Add..., select Color and click OK.
5. In the Name and Value fields that appear, enter correct_answer
and #00CC00
, respectively, then save the file.
6. Repeat Steps 4 and 5, but enter incorrect_answer
and #FF0000
.