Background images in Jetpack Compose

Compose has no background-image modifier, but it has two clean ways to put a picture behind a screen. Here is which one to use, and how to keep the image full-screen, sharp and light on memory.

10 min read
Smartphone with a teal brushed metal texture filling its screen, next to a curled sheet of the same metal on dark concrete
In short
  • For a static background, use Modifier.paint with ContentScale.Crop and sizeToIntrinsics = false. In a Box, give the image matchParentSize().
  • Draw the image edge to edge and pad only the content with safeDrawingPadding().
  • A bitmap in plain drawable/ is scaled up on dense screens. Put large backgrounds in drawable-nodpi.
  • Scaffold paints an opaque color over your image. Set containerColor = Color.Transparent.
10.4 MBDecoded size of one full-screen image on a 1080×2400 phone
9xMemory cost of a bitmap left in plain drawable/ on a 3x phone
4.5:1Minimum contrast for body text (WCAG AA)

Compose has no backgroundImage modifier. You put a picture behind a screen in one of two ways: an Image at the bottom of a Box, or Modifier.paint on the container itself. This guide shows both. Then it covers what decides whether the result looks right on every Android phone: edge-to-edge insets, ContentScale, density folders, memory, Scaffold, tiling and dark mode.

The checks are the same whether your own team builds the screens or you hire Android app developers for the job. Every background has a pixel size, a memory cost and a contrast problem, and you can measure all three before release.

If you have read our guides to background images in Flutter or SwiftUI, the budgets will look familiar. Only the APIs change.

Should you use a Box or Modifier.paint?

Use Modifier.paint for a static background that never changes. Use a Box with an Image when the background needs its own modifiers, such as blur, a crossfade or a parallax offset.

NeedModifier.paintBox + Image
Who decides the sizeThe container, if sizeToIntrinsics = falseThe content, if the image uses matchParentSize()
Static full-screen or card backgroundYes, one lineWorks, a few more lines
Tint or color filtercolorFilter parametercolorFilter on the Image
Blur, crossfade, parallaxAwkwardEasy, the image is its own node
Remote image (Coil)rememberAsyncImagePainterAsyncImage

In a Box, give the image Modifier.matchParentSize(), not fillMaxSize(). A Box takes the size of its largest child. An Image with fillMaxSize() inside a Box that wraps its content can push the box to the full screen, and a card that should be 120 dp tall becomes as tall as the phone. matchParentSize() is measured after the other children, so the text decides the size and the image only fills it.

How do you set a background with Modifier.paint?

Add Modifier.paint to the root container with a painter, ContentScale.Crop and sizeToIntrinsics = false:

Column(
    modifier = Modifier
        .fillMaxSize()
        .paint(
            painter = painterResource(R.drawable.bg_brushed_metal),
            sizeToIntrinsics = false,
            contentScale = ContentScale.Crop
        )
) {
    Text("Welcome")
}

Three details catch people out:

  1. Turn off sizeToIntrinsics. It is true by default. Then the painter's pixel size feeds into layout, and a large image can make the container larger than you meant.
  2. Put the modifier after the size. fillMaxSize() comes first, so the painter has a full-screen area to cover.
  3. Use lowercase resource names. Android accepts only a-z, 0-9 and underscores in drawable names. bg-kraft.webp fails the build; bg_kraft.webp works.

How do you make the image fill the whole screen?

Draw the background edge to edge and pad only the content. Since Android 15, apps that target API 35 are edge to edge by default: the window runs under the status bar and the navigation bar. On older versions, call enableEdgeToEdge() in your activity before setContent.

Then split the work between two layers:

Box(modifier = Modifier.fillMaxSize()) {
    Image(
        painter = painterResource(R.drawable.bg_brushed_metal),
        contentDescription = null,
        contentScale = ContentScale.Crop,
        modifier = Modifier.matchParentSize()
    )
    Column(modifier = Modifier.safeDrawingPadding()) {
        Text("Welcome")
    }
}

This is also the Box version of a background. The image comes first, so it draws first and sits under everything else, and contentDescription = null tells TalkBack to skip it as decorative. The image ignores the insets and fills the window. The column uses safeDrawingPadding(), so text stays clear of the camera cutout, the system bars and the keyboard. If you pad the outer Box instead, the background stops short of the bars and leaves a strip of window color. The edge-to-edge setup guide lists which inset types to use where.

Stop the jump when the keyboard opens

On a login screen the keyboard shrinks the content area. If the image is sized by the same padded container, it rescales every time the keyboard opens. Keep the image in the unpadded layer, as above, and only the content moves. ContentScale.Crop on a full-window image does not change when the keyboard appears.

Which ContentScale should a background use?

Use ContentScale.Crop for almost every full-screen background. It keeps the aspect ratio, fills the bounds and crops what overflows. The default for Image is ContentScale.Fit, which leaves empty bands, so set it explicitly.

ContentScaleWhat it doesUse it for
CropFills the bounds, keeps the ratio, crops the restFull-screen and card backgrounds
Fit (default)Shows the whole image, leaves empty bandsArtwork that must not be cropped
FillBoundsStretches width and height separatelyFlat colors and soft gradients only
FillWidth / FillHeightMatches one side, may crop or band the otherHeaders with a fixed height
NoneNatural size, centeredSmall marks, rarely backgrounds

Plan for the portrait crop

Most Android phones are around 9:20 in portrait. A 4:3 file, such as our 1600×1200 backgrounds, loses most of its left and right sides. Keep the key area near the center, or move the crop with alignment = Alignment.TopCenter when the subject sits at the top. On tablets and unfolded foldables the screen is close to square, so the same image shows much more of its width. Calm surfaces with no focal point, like the brushed metal texture, look right on both.

How big should the image be?

Make the file as large as the biggest screen you support, in physical pixels, and put it where Android will not scale it. The size on disk is not the real cost. A decoded bitmap in the default ARGB_8888 format takes 4 bytes per pixel, whatever the file format.

ImagePixelsDecoded in memory
1080×2400 phone screen2.6 millionabout 10.4 MB
1440×3120 phone screen4.5 millionabout 18 MB
Web Backgrounds file, in drawable-nodpi1600×1200about 7.7 MB
Same file in plain drawable/ on a 3x phone4800×3600about 69 MB

Mind the density folders

The last row is the classic Android mistake. A bitmap in plain drawable/ is treated as mdpi, the 1x baseline. On an xxhdpi phone, the resource loader scales it up three times in each direction before it reaches your composable, and one background takes the memory of nine. Pick one of two fixes:

  1. One file: put it in drawable-nodpi/. Android loads it at its real size and ContentScale.Crop does the rest.
  2. Several files: export sized copies to drawable-xhdpi, drawable-xxhdpi and drawable-xxxhdpi. Each device gets only the copy it needs when the app ships as an App Bundle.

The screen density guide lists the scale factor of every bucket. Convert PNG and JPEG backgrounds to WebP before you add them. Android Studio does it from the context menu. Google's WebP documentation puts lossy WebP at 25 to 34 percent smaller than a comparable JPEG.

How do you keep text readable on top?

Darken the image under the text. One extra modifier is enough:

Image(
    painter = painterResource(R.drawable.bg_brushed_metal),
    contentDescription = null,
    contentScale = ContentScale.Crop,
    modifier = Modifier
        .matchParentSize()
        .drawWithContent {
            drawContent()
            drawRect(Color.Black.copy(alpha = 0.45f))
        }
)

A black layer at 40 to 55 percent is a common start for white text on a busy texture. When the text sits only at the bottom, draw a Brush.verticalGradient from transparent to black instead, so the rest of the image stays bright. Modifier.blur softens a busy photo, but it works only on Android 12 and later and is ignored on older versions, so never rely on blur alone for contrast.

The target is the WCAG contrast minimum: 4.5:1 for body text and 3:1 for large text. Measure it on the brightest area that can sit behind text. Our article on readable text on background images shows how.

Why is the background hidden behind a Scaffold?

Scaffold paints its own containerColor, which defaults to the opaque background color of your Material theme. Anything you draw behind it is covered. Make the scaffold transparent and draw the image outside it:

Box(modifier = Modifier.fillMaxSize()) {
    Image(
        painter = painterResource(R.drawable.bg_dark_slate),
        contentDescription = null,
        contentScale = ContentScale.Crop,
        modifier = Modifier.matchParentSize()
    )
    Scaffold(containerColor = Color.Transparent) { innerPadding ->
        LazyColumn(contentPadding = innerPadding) { /* rows */ }
    }
}

A LazyColumn has no background of its own, but Card and Surface rows do. Give them a translucent container color if the texture should show through. A TopAppBar also paints a solid color; pass TopAppBarDefaults.topAppBarColors(containerColor = Color.Transparent) if the bar should float over the image.

How do you tile a small texture?

Use a ShaderBrush with an ImageShader and repeat it on both axes. It replaces the old XML android:tileMode attribute:

val tile = ImageBitmap.imageResource(R.drawable.tile_linen)
val brush = remember(tile) {
    ShaderBrush(ImageShader(tile, TileMode.Repeated, TileMode.Repeated))
}
Box(modifier = Modifier.fillMaxSize().background(brush))

The shader repeats the bitmap at its decoded pixel size, not in dp. A 512-pixel tile in drawable-nodpi repeats every 512 physical pixels, which is about 170 dp on a 3x phone. Wrap the brush in remember so it is not rebuilt on every recomposition. Edges that do not match show as a grid, so check the tile first with our guide to seamless tileable textures. The Brush documentation shows the other tile modes and the gradient brushes, which need no image file at all.

How do you switch backgrounds for dark mode?

Let resource qualifiers do it. Put the dark file under the same name in drawable-night-nodpi/. painterResource(R.drawable.bg_paper) then loads the right file and switches when the user changes the system theme. No code is needed.

If the app has its own theme switch, read the app's setting or isSystemInDarkTheme() and pick the resource in code. In both cases, a dark variant is not the light file with the brightness turned down. Lower the contrast inside the texture, remove pure white highlights and keep the tone near your dark surface color. Our notes on using backgrounds in dark mode cover the visual side, and the dark slate stone texture is a ready dark base.

Should backgrounds be bundled or loaded from a URL?

Bundle the backgrounds that appear on first launch and on core screens. They work offline and are ready on the first frame.

Load from a URL when backgrounds change often, such as seasonal themes from a CMS. Then:

  1. Use Coil's AsyncImage with ContentScale.Crop, and pass a ColorPainter in the background's darkest tone as the placeholder. It avoids a white flash.
  2. Let Coil size the request from the layout. It decodes to the size of the composable, so a 4000-pixel original does not land in memory at full size.
  3. Serve a file sized for phones anyway. The download still costs data.
  4. Keep Coil's memory and disk caches on, so a background shared by several screens is not fetched and decoded again.

What about the splash screen?

Keep the splash plain and show the rich background on the first real screen. Since Android 12 every app gets a system splash screen: an icon centered on a solid color. You can set the color and the icon through the SplashScreen API, but you cannot put a full-bleed image there. A pattern that works:

  1. Splash: windowSplashScreenBackground set to the darkest tone of your background.
  2. First screen: the same color as the window background under the image, so the image appears without a flash.
  3. Onboarding: one background per step at most, all from the same family of textures.

Our guide to splash screen backgrounds covers this hand-off in more detail.

A checklist before you ship

  • Static backgrounds use Modifier.paint with sizeToIntrinsics = false, or an Image with matchParentSize() inside a Box.
  • ContentScale.Crop is set explicitly, not left at the Fit default.
  • The image draws edge to edge, and only the content uses inset padding.
  • The key area of the image survives a portrait crop and a square tablet screen.
  • Large bitmaps live in drawable-nodpi or in sized density folders, never in plain drawable/.
  • Text on top reaches 4.5:1 contrast on the brightest part of the image.
  • The image has contentDescription = null.
  • Scaffold and app bars are transparent where the image should show.
  • Dark mode loads its own file from a -night folder, not a dimmed copy.
  • The splash color matches the first screen.

Need a starting point? Browse background textures for calm surfaces that work behind text, or read background images in React Native if part of your app is cross-platform.

Questions about Jetpack Compose backgrounds

How do I set a background image in Jetpack Compose?

Add Modifier.paint to your root container with painterResource, ContentScale.Crop and sizeToIntrinsics = false. Or put an Image with ContentScale.Crop and Modifier.matchParentSize() as the first child of a Box.

Why does my Compose background image leave a strip under the status bar?

The image is inside a padded container. Draw it edge to edge in an unpadded layer, call enableEdgeToEdge() on Android 14 and older, and apply safeDrawingPadding() only to the content.

Why is my background image hidden behind a Scaffold?

Scaffold paints its containerColor, which defaults to the opaque theme background. Set containerColor = Color.Transparent and draw the image outside the Scaffold, in a Box behind it.

Why does a background image use so much memory on Android?

A bitmap in plain drawable/ is treated as mdpi and scaled up on dense screens, so a 1600 by 1200 file becomes 4800 by 3600 on a 3x phone, about 69 MB. Put it in drawable-nodpi or ship sized density variants.

How do I repeat a small texture as a background in Compose?

Load it with ImageBitmap.imageResource, wrap it in ShaderBrush(ImageShader(bitmap, TileMode.Repeated, TileMode.Repeated)), remember the brush, and pass it to Modifier.background.

Keep reading

Built for the web.
Free to download.