← All courses

Resources, Themes & Dark Mode

🗓 May 31, 2026 ⏱ 2 min read

What are resources?

Resources are everything that isn’t code: text, colors, dimensions, images, and styles. Android keeps them in the res/ folder so they can be reused and swapped automatically based on language, screen size or theme.

Strings (and why you should never hard-code text)

Put all user-facing text in res/values/strings.xml. This makes translation trivial and keeps text consistent.

<resources>
    <string name="app_name">My App</string>
    <string name="welcome">Welcome back!</string>
</resources>
binding.title.text = getString(R.string.welcome)

To add Hindi, create res/values-hi/strings.xml with the same keys — Android picks the right file based on the device language.

Colors and dimensions

<!-- res/values/colors.xml -->
<color name="purple">#7C3AED</color>

<!-- res/values/dimens.xml -->
<dimen name="screen_padding">16dp</dimen>

Themes and styles

A theme applies app-wide colors and fonts; a style is a reusable bundle of attributes for a view. Material 3 themes give you a consistent look for free.

<style name="Theme.MyApp" parent="Theme.Material3.DayNight">
    <item name="colorPrimary">@color/purple</item>
</style>

Dark mode

If your theme extends DayNight, you get dark mode almost for free. Provide dark colors in res/values-night/colors.xml and Android switches automatically when the user enables dark mode.

// force a mode if you want a toggle in your app
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)

Common mistakes

  • Hard-coding text and colors in layouts instead of using resources.
  • Hard-coding a white background that looks broken in dark mode — use theme attributes like ?attr/colorSurface.
  • Forgetting to mirror string keys when adding a new language.
Summary: Put text in strings.xml, colors in colors.xml, and use a DayNight theme so dark mode and translations just work.