How to Use Strings, Colors, and Drawables in Jetpack Compose

Compose can use Android resources directly: stringResource() for localized text, colorResource() for legacy color resources, and painterResource() for drawables. Prefer MaterialTheme colors for themeable UI, and use string resources for user-visible text and content descriptions.

Strings

Text(text = stringResource(R.string.profile_title))
Icon(
    imageVector = Icons.Default.Edit,
    contentDescription = stringResource(R.string.cd_edit_profile)
)

Use formatted resources instead of concatenating translated text:

Text(stringResource(R.string.greeting, user.name))

Colors

For app UI, prefer the semantic palette provided by Material 3:

Text(color = MaterialTheme.colorScheme.onSurface, text = title)

colorResource(R.color.brand_accent) is useful when integrating an existing resource color, but semantic theme colors adapt better to dark mode and dynamic color.

Drawables

Image(
    painter = painterResource(R.drawable.article_cover),
    contentDescription = stringResource(R.string.cd_article_cover)
)

Use contentDescription = null only for truly decorative artwork. Interactive and informational visuals need a meaningful localized description.

Practical rules

  • Keep user-facing text in strings.xml for localization.
  • Avoid hard-coded colors when a Material semantic color expresses the role.
  • Use vector drawables or ImageVector icons for scalable icons.
  • Test contrast in light and dark themes.

For theme design, see Material Theme in Jetpack Compose.