Material 3 Themes, Colors and Dark Mode in Jetpack Compose
โ† BACK TO WRITING
October 15, 2026

By , Android developer & software engineer

Material 3 Themes, Colors and Dark Mode in Jetpack Compose

Give your Android app its own brand colors, a custom font and automatic dark mode with Material 3 themes in Jetpack Compose. Beginner friendly.

Our fruit app works well now. It has a list, a details screen, a ViewModel, a top bar and bottom tabs. But it still uses the default purple colors from the template, and some text uses hard-coded gray. In this part we will learn about Material 3 themes and dark mode in Jetpack Compose. You will give your app its own brand colors, a custom font, and a dark mode that switches on by itself. If you missed the last lesson, read Part 10: Scaffold, Top App Bar and Bottom Navigation first.

What Is a Theme?

Think of a theme like a uniform for a school. Every student wears the same colors, so the school looks like one team. A theme does the same for your app. You choose the colors, fonts and shapes one time, and every screen uses them.

If you want to change your brand color later, you change it in one place. You do not need to search through 20 screens. ๐ŸŽ‰

The 3 Theme Files the Template Made

When you created the project with the "Empty Activity" template, Android Studio made a folder called ui/theme. Open it in the Project panel. You will see 3 files:

  1. Color.kt โ€“ your color values (like Purple80, Pink40).
  2. Theme.kt โ€“ the MyFirstAppTheme function. It picks the right colors for light or dark mode.
  3. Type.kt โ€“ your text styles (font size, font weight, font family).

Remember MainActivity? It wraps everything inside MyFirstAppTheme { ... }. That is why every composable inside it can use the theme.

MaterialTheme.colorScheme and MaterialTheme.typography

Inside any composable, you can ask the theme for values:

  • MaterialTheme.colorScheme.primary โ€“ the main brand color.
  • MaterialTheme.colorScheme.onPrimary โ€“ the color for text on top of primary.
  • MaterialTheme.colorScheme.surface โ€“ the background of cards and screens.
  • MaterialTheme.colorScheme.onSurfaceVariant โ€“ a softer text color, good for small details.
  • MaterialTheme.typography.titleLarge, bodyMedium, labelSmall โ€“ ready-made text styles.

The word "on" is important. onPrimary means "the color that is easy to read on primary". Material 3 always gives you matching pairs, so your text never disappears into the background.

Step 1: Choose Your Brand Colors

Let's make our fruit app green, like fresh leaves. ๐Ÿƒ

Tip: Picking good colors is hard. Use the free Material Theme Builder website. Choose one main color, and it makes a full light and dark color set for you. It can even export a Jetpack Compose theme.

Open ui/theme/Color.kt and replace everything with this:

package com.example.myfirstapp.ui.theme

import androidx.compose.ui.graphics.Color

// Light mode colors
val Green40 = Color(0xFF2E7D32)
val Orange40 = Color(0xFFE65100)
val Leaf40 = Color(0xFF558B2F)

// Dark mode colors (lighter, so they look good on a dark background)
val Green80 = Color(0xFFA5D6A7)
val Orange80 = Color(0xFFFFB74D)
val Leaf80 = Color(0xFFC5E1A5)

Let's understand it:

  • Color(0xFF2E7D32) makes a color from a hex code. 0xFF means "fully visible". 2E7D32 is the green.
  • We make two versions of each color. Dark colors for light mode, light colors for dark mode.
  • If your package name is different, keep your own first line.

Step 2: Update Theme.kt

Open ui/theme/Theme.kt. Replace the whole file with this:

package com.example.myfirstapp.ui.theme

import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext

private val LightColorScheme = lightColorScheme(
    primary = Green40,
    secondary = Leaf40,
    tertiary = Orange40
)

private val DarkColorScheme = darkColorScheme(
    primary = Green80,
    secondary = Leaf80,
    tertiary = Orange80
)

@Composable
fun MyFirstAppTheme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    dynamicColor: Boolean = false,
    content: @Composable () -> Unit
) {
    val colorScheme = when {
        dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
            val context = LocalContext.current
            if (darkTheme) dynamicDarkColorScheme(context)
            else dynamicLightColorScheme(context)
        }
        darkTheme -> DarkColorScheme
        else -> LightColorScheme
    }

    MaterialTheme(
        colorScheme = colorScheme,
        typography = Typography,
        shapes = AppShapes,
        content = content
    )
}

Let's understand it:

  • lightColorScheme(...) and darkColorScheme(...) build full color sets. You only give the colors you want to change. Material 3 fills in the rest.
  • isSystemInDarkTheme() checks the phone setting. If the user turned on dark mode, it returns true. So dark mode works automatically.
  • dynamicColor is about a special Android 12+ feature (see below). We changed the default from true to false.
  • Build.VERSION_CODES.S means Android 12.
  • shapes = AppShapes is new. We will create AppShapes in Step 5. Until then, this line will be red. That is normal.

What Is Dynamic Color?

On Android 12 and newer, the phone can make colors from the user's wallpaper. If the wallpaper is blue, apps become blue. This is called dynamic color.

It looks nice. But it also means your brand colors are ignored on new phones. That is why many beginners say, "I changed my colors, but nothing happened!" The answer: dynamic color was on.

  • dynamicColor: Boolean = false โ€“ your colors always show. โœ…
  • dynamicColor: Boolean = true โ€“ wallpaper colors on Android 12+, your colors on older phones.

Both are fine. Choose what you like. For learning, keep it false so you can see your changes.

Step 3: Use Theme Colors Instead of Color.Gray

In Part 7 we wrote the price text in Color.Gray. Gray looks OK in light mode, but in dark mode it can be hard to read. Let's use a theme color instead. Here is the full FruitRow:

@Composable
fun FruitRow(fruit: Fruit, onClick: () -> Unit) {
    Card(
        onClick = onClick,
        modifier = Modifier
            .fillMaxWidth()
            .padding(horizontal = 16.dp, vertical = 6.dp),
        colors = CardDefaults.cardColors(
            containerColor = MaterialTheme.colorScheme.surfaceVariant
        )
    ) {
        Row(
            modifier = Modifier.padding(16.dp),
            verticalAlignment = Alignment.CenterVertically
        ) {
            Text(text = fruit.emoji, fontSize = 32.sp)
            Spacer(modifier = Modifier.width(16.dp))
            Column {
                Text(
                    text = fruit.name,
                    style = MaterialTheme.typography.titleMedium,
                    fontWeight = FontWeight.Bold,
                    color = MaterialTheme.colorScheme.onSurface
                )
                Text(
                    text = "เงณ${fruit.price} per kg",
                    style = MaterialTheme.typography.bodyMedium,
                    color = MaterialTheme.colorScheme.primary
                )
            }
        }
    }
}

Let's understand it:

  • CardDefaults.cardColors(containerColor = ...) sets the card background from the theme.
  • The fruit name uses onSurface, so it is readable in both modes.
  • The price now uses primary โ€“ our green. It changes to light green in dark mode by itself.
  • style = MaterialTheme.typography.titleMedium uses a ready-made text size. No more guessing fontSize numbers.

If you see red words, click on them and press Alt+Enter to import. Tricky imports:

  • androidx.compose.material3.CardDefaults
  • androidx.compose.material3.MaterialTheme
  • androidx.compose.ui.text.font.FontWeight

Tip: Search your project for Color.Gray, Color.Black and Color.White (press Ctrl+Shift+F). Each one is a place where dark mode might look wrong. Replace them with theme colors.

Step 4: Preview Light and Dark Side by Side

You don't need to change your phone setting every time. You can preview both modes in Android Studio:

@Preview(name = "Light", showBackground = true)
@Preview(
    name = "Dark",
    showBackground = true,
    uiMode = Configuration.UI_MODE_NIGHT_YES
)
@Composable
fun FruitRowPreview() {
    MyFirstAppTheme {
        Surface {
            FruitRow(
                fruit = Fruit("Mango", "๐Ÿฅญ", 120),
                onClick = {}
            )
        }
    }
}

Let's understand it:

  • You can put two @Preview lines on one function. You get two previews.
  • uiMode = Configuration.UI_MODE_NIGHT_YES tells the preview "pretend dark mode is on".
  • We wrap the row in MyFirstAppTheme and Surface. Surface paints the correct background color.
  • Import Configuration from android.content.res.Configuration (press Alt+Enter and choose this one).

Open the Split view at the top right of the editor. You will see a light card and a dark card. ๐ŸŽ‰

Tip: If your Fruit class now has more fields (for example from later parts), add them in the preview too.

Step 5: A Custom Font

Default fonts are fine, but a custom font gives your app personality. Let's use Poppins, a free font from Google Fonts.

  1. Go to fonts.google.com, search Poppins, and download it.
  2. Unzip the file. Find Poppins-Regular.ttf and Poppins-Bold.ttf.
  3. Rename them to poppins_regular.ttf and poppins_bold.ttf. Android resource names must be lowercase, with only letters, numbers and underscores.
  4. In Android Studio, right-click the res folder โ†’ New โ†’ Android Resource Directory. Choose resource type font and click OK.
  5. Copy the two .ttf files into res/font.

Now open ui/theme/Type.kt and replace it with this:

package com.example.myfirstapp.ui.theme

import androidx.compose.material3.Typography
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import com.example.myfirstapp.R

val Poppins = FontFamily(
    Font(R.font.poppins_regular, FontWeight.Normal),
    Font(R.font.poppins_bold, FontWeight.Bold)
)

private val default = Typography()

val Typography = Typography(
    titleLarge = default.titleLarge.copy(fontFamily = Poppins),
    titleMedium = default.titleMedium.copy(fontFamily = Poppins),
    bodyLarge = default.bodyLarge.copy(fontFamily = Poppins),
    bodyMedium = default.bodyMedium.copy(fontFamily = Poppins),
    labelLarge = default.labelLarge.copy(fontFamily = Poppins)
)

Let's understand it:

  • FontFamily(...) groups the regular and bold files into one family.
  • Typography() with no arguments gives the default Material 3 styles. We take them and only change the font with .copy(fontFamily = Poppins).
  • Every Text that uses MaterialTheme.typography.bodyMedium (and the others) now shows Poppins.
  • R must be your app's R. Change com.example.myfirstapp.R to your package name.

Step 6: Shapes (Quick Look)

Shapes control how round the corners are on cards, buttons and dialogs. Create a new file ui/theme/Shape.kt:

package com.example.myfirstapp.ui.theme

import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Shapes
import androidx.compose.ui.unit.dp

val AppShapes = Shapes(
    small = RoundedCornerShape(8.dp),
    medium = RoundedCornerShape(16.dp),
    large = RoundedCornerShape(24.dp)
)

Now the red AppShapes line in Theme.kt is fixed. Cards use the medium shape, so all your fruit cards get rounder 16.dp corners. Want sharp corners everywhere? Change the numbers to 0.dp.

Step 7: Test Dark Mode on Your Phone

Run the app. Then:

  1. Pull down the notification shade on your phone or emulator.
  2. Tap Dark theme (or go to Settings โ†’ Display โ†’ Dark theme).
  3. Go back to your app.

The app switches to dark colors by itself. The price turns light green, the cards turn dark. You wrote zero extra code for this. ๐ŸŽ‰

Common Errors

  • "I changed colors but the app looks the same." Dynamic color is on and you are on Android 12+. Set dynamicColor: Boolean = false in Theme.kt.
  • "Unresolved reference: poppins_regular." The file name has capital letters or a dash. Rename it to lowercase with underscores, then use Build โ†’ Rebuild Project.
  • "Unresolved reference: R" in Type.kt. Import your own app's R class, like com.example.myfirstapp.R, not android.R.
  • Text is black on a dark background. Somewhere you still use a hard-coded Color.Black, or the content is not inside a Surface or Scaffold. Use theme colors.
  • "Unresolved reference: Configuration." Import android.content.res.Configuration.

Try It Yourself

  1. Use the Material Theme Builder to pick an orange brand color, export the colors, and paste them into Color.kt.
  2. Set dynamicColor = true, change your phone wallpaper, and see your app change color.
  3. Make the fruit name on FruitDetailsScreen use MaterialTheme.typography.headlineMedium and colorScheme.primary.

Frequently Asked Questions

Can I force my app to always be dark? Yes. In MainActivity, call MyFirstAppTheme(darkTheme = true) { ... }. But most users prefer the app to follow their phone setting.

Should I keep dynamic color on or off? Off is good if your brand color matters (like a shop app). On is nice for simple tools and feels personal. Both are correct.

Why do dark mode colors need to be lighter? Dark green text on a black background is hard to read. Lighter colors have better contrast on dark backgrounds, so your text stays clear.

Quick Recap

  • The theme lives in ui/theme: Color.kt, Theme.kt, Type.kt (and our new Shape.kt).
  • Use MaterialTheme.colorScheme and MaterialTheme.typography instead of hard-coded colors and sizes.
  • lightColorScheme and darkColorScheme hold your brand colors.
  • Dynamic color uses wallpaper colors on Android 12+. Turn it off to see your own colors.
  • isSystemInDarkTheme() makes dark mode automatic.
  • @Preview(uiMode = Configuration.UI_MODE_NIGHT_YES) previews dark mode.
  • Custom fonts go in res/font with lowercase names.

Our app looks beautiful now. Next, let's replace those emojis with real fruit photos from the internet.

Part 12: Load Images from the Internet in Jetpack Compose with Coil

Next in Android for Beginners โ†’
Load Images from the Internet in Jetpack Compose with Coil
ยฉ 2026 SHAKIL AHMED. SYSTEM: ANTIGRAVITY OS v1.0