Programmatically retrieve color from a resource using ContextCompat, which does not ignore the night qualifier

I am currently using ContextCompat.getColorbut not getting the right color. When an application adheres to the night resource qualifier, ContextCompat selects a color from values/colors.xml, rather than values-night/colors.xml.

I have tried apporaches similar to this one https://stackoverflow.com/a/2129609/2129 , using a theme with one residing in values/styles.xmland values-night/styles.xml, but it seems that the color is precompiled using a resource without a qualifier -night.

+4
source share
1 answer

, :

int currentNightMode = getResources().getConfiguration().uiMode
        & Configuration.UI_MODE_NIGHT_MASK;
switch (currentNightMode) {
    case Configuration.UI_MODE_NIGHT_NO:
        // Night mode is not active, we're in day time
    case Configuration.UI_MODE_NIGHT_YES:
        // Night mode is active, we're at night!
    case Configuration.UI_MODE_NIGHT_UNDEFINED:
        // We don't know what mode we're in, assume notnight
}

: https://medium.com/@chrisbanes/appcompat-v23-2-daynight-d10f90c83e94#.l2fswuy4z

+2

All Articles