4

I'm currently using ContextCompat.getColor, however it's not fetching the correct colour. When the app is adhering to the night resource qualifier, ContextCompat fetches the color from values/colors.xml and not values-night/colors.xml.

I've tried apporaches like this https://stackoverflow.com/a/13952929/333733 using a theme with one residing in values/styles.xml and values-night/styles.xml but it seems the color is precompiled using the resource folder without the -night qualifier.

Community
  • 1
  • 1
gbhall
  • 13,139
  • 9
  • 37
  • 42

1 Answers1

2

You can check for which mode the theme is in yourself:

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
}

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

gbhall
  • 13,139
  • 9
  • 37
  • 42