0

I want to load different resource files according to Dark/Light theme in Jetpack Compose, but it is not working.

What should I do next?

Image(
    modifier = Modifier.align(Alignment.CenterHorizontally),
    painter = painterResource(id = R.drawable.ic_daynight),
    contentDescription = null
)

res/drawable/ic_daynight.xml:

drawable ic_daynight

res/drawable-night/ic_daynight.xml:

drawable-night ic_daynight

Res folder:

drawable image

theme.xml:

theme.xml

Jero
  • 1
  • 1

1 Answers1

1

It is definitely possible in the way you've described - see my answer to a similar post here.

Maybe the difference here is that you're using an old Compose version? Make sure you're using version 1.0.1 or above for this to work as you expect. I assume you want this to take effect when you set your device in dark mode.

Martyna Maron
  • 371
  • 4
  • 19