Challenge 2: Edit a String Resource — Solution Walkthrough
1. Open app/res/layout/activity_main.xml (Project view, or switch the
left panel to "Project" if using the default "Android" view to see
the real file path).
2. Find the TextView showing the greeting — its "android:text" attribute
will reference a string resource, e.g.:
android:text="@string/hello_world"
(the exact name depends on the template version; it's whatever
@string/... value appears on the TextView showing "Hello World!").
3. Open app/res/values/strings.xml and find the matching entry, e.g.:
Hello World!
4. Change the text inside the tag, e.g.:
Hello, Android!
5. Re-run the app (Run ▶) without touching MainActivity.kt or
activity_main.xml at all.
Expected result:
The emulator now shows "Hello, Android!" instead of "Hello World!" —
proof that the text was never hardcoded in the layout or the Kotlin
code, only referenced by name via @string/hello_world.
Notes:
- This resource-indirection pattern (name in strings.xml, referenced
everywhere else by @string/name or R.string.name) is exactly what
makes translating an app to another language possible later — a
translated strings.xml (e.g. strings.xml in a values-fr/ folder) swaps
in automatically based on the device's language, with zero code
changes.
- The same idea applies to colors.xml (@color/...) and dimens.xml
(@dimen/...), covered more fully in Chapter 8 (Resources & Styling).