Defining Resources

Almost all resources are defined with XML (see Using Resources). Thankfully, the XML is precompiled at build time so you don’t have to pay a performance penalty for parsing it when the program runs.

Strings

Instead of hard-coding text strings in our program code and layouts, we store them all in one place: the strings.xml resource file in the res/values folder. That will make it much easier to translate the strings when it comes time to internationalize your app for foreign markets. Here are the definitions for all the strings we’ve used so far in the Tic-Tac-Toe program:

ticTacToev1/src/main/res/values/strings.xml
 
<?xml version="1.0" encoding="utf-8"?>
 
<resources>
 
<string​ name=​"app_name"​​>​UT3​</string>
 
<string ...

Get Hello, Android, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.