Issue
I have a logo on my splash screen and two files: logo_night.png and logo_day.png
How can i change this logo that will change depending on the theme of the app using these two files?
Solution
The usual way is to use a night resource qualifier, so if you're using a dark theme it pulls the named resource from the equivalent night folder if it exists there.
You have three basic options with this I think:
just call them both
logo.png, but put one version indrawableand the other indrawable-night. That way, whenever you refer to@drawable/logoit'll pull the correct version depending on the theme. If you have multiple density versions, indrawable-hdpietc, you'll need them indrawable-night-hdpietc. (the qualifier order matters)if you're making your splash in the usual way, where you create a splash drawable with a background layer and your logo drawable on another layer, you could just make a
nightvariant of this instead (indrawable-night). Each version can explicitly refer tologo_dayorlogo_nightand you can just keep those PNGs in the normaldrawablefolderor you can make a
nightversion of your splash theme, and explicitly set the background to the dark version of your splash drawable instead. Both your splash drawables can stay in the normaldrawablefolder
So basically, something's gotta get a version in a night-qualified resource folder, so it can provide an alternative resource for dark mode. It's up to you which resource in that hierarchy you want to make the night version of (or you can do it for all of them if you want).
Also bear in mind that your splash theme (if you're doing it that way) follows the system's dark mode setting. If you're implementing a toggle in your app, and you set it to dark mode, the splash will still show up as the light variant if that's what the device is set to. That theme is set before your app starts and gets to work out if it should be in dark or light mode
Answered By - cactustictacs
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.