Anatomy of an Android App

Sep 10 2024 · Kotlin 1.9.23, Android 14, Android Studio Iguana

Lesson 02: Use Android Resources

Demo

Episode complete

Play next episode

Next

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Managing Strings in Your App

One of the most important elements of any app is the text, or strings, displayed on the screen. As you advance in your Android development career, you’ll want to master the ins and outs of using strings.

<resources>
  <string name="app_name">Kodeco Chat</string>
</resources>
<resources>
  <string name="app_name">Kodeco Chat</string>
  <string name="chat_display_default">Messages will display here</string>
  <string name="chat_entry_default">Type your text here</string>
  <string name="send_button">Send</string>
  <string name="chat_entry_label">Enter Chat Text</string>
  <string name="greeting">Ciao</string>
</resources>
setContent {
  KodecoChatTheme {
    Surface(modifier = Modifier.fillMaxSize()) {
      Box(modifier = Modifier.fillMaxSize()) {
        Column(
          Modifier
            .fillMaxSize()
            .padding(50.dp)
        )
        {
          OutlinedTextField(
            value = "",
            onValueChange = {  },
            label = { Text("Label") }
          )
          Greeting(
            name = "Android"
          )
        }
      }
    }
  }
}
<img src="images/add_label.png" width="250" height="500">
@Composable
fun Greeting(name: String) {
  val greetingText = stringResource(id = R.string.greeting)
  Text(
    text = "$greetingText, $name!"
  )
}

Adding Images

Next, you’ll see how to add some image assets to your app.

Box() {
  Icon(
    painter = painterResource(id = R.drawable.kodeco_logo_back),
    contentDescription = null,
    tint = Color(0xFFFF5A00)
  )
  Icon(
    painter = painterResource(id = R.drawable.kodeco_logo),
    contentDescription = null,
    tint = Color.White
  )
}
<img src="images/add_vector_asset.png" width="250" height="500">
android:roundIcon="@mipmap/ic_launcher_round"
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
  <background android:drawable="@drawable/kodeco_logo" />
  <foreground android:drawable="@drawable/kodeco_logo_back" />
  <monochrome android:drawable="@drawable/kodeco_logo" />
</adaptive-icon>
<img src="images/adaptive_icon.png" width="250" height="500" style="margin-right: 10px;">
<img src="images/app_icon2.png" width="250" height="500">
<img src="images/app_icon3.png" width="250" height="500">
See forum comments
Cinema mode Download course materials from Github
Previous: Your First Android Project Next: Conclusion