Reputation: 6703
I have one page where I need to use colors from night mode regardless of current app/phone theme.
Let's say I have colorAppBg
declared in both values/colors.xml
and values-night/colors.xml
with different hex.
How can I get colorAppBg
from values-night
folder for 1 specific fragment?
Upvotes: 1
Views: 258
Reputation: 61
That's the solution:
fun getNightModeColor(@ColorRes colorResId: Int, context: Context): Int {
val nightModeContext = context.createConfigurationContext(
Configuration(context.resources.configuration).apply {
uiMode = Configuration.UI_MODE_NIGHT_YES
}
)
return ContextCompat.getColor(nightModeContext, colorResId)}
Upvotes: 0