Search code examples
androidandroid-layouttextcolor

textColor is being ignored in a night mode


I have a few textViews with a property android:textColor="@color/textColor".

Color textColor is defined in two files: colors.xml and colors-night.xml

#000000 and #4183d7 respectively.

I allow users to change app theme:

  1. AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
  2. AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);

But if mobile is set to night mode and user tries to set the app to light mode, all textViews become white (howewer it must be black)


Solution

  • If dark mode is enabled on a phone, but not in your app - system applies color inversion. To disable it, we need to use android:forceDarkAllowed="false"