androidcolorsdrawableandroid-darkmode

Android Q dark mode changes color of drawable form white to gray


I put an almost white icon (drawable object) on a bright red background (drawn rectangle). When I switch in dark mode, Android 10 changes the color of the icon into dark gray. However, I want this icon to remain in its original color in dark mode. It is the same with the light red drawn rectangle background. Android 10 changes it to a dark red background.

I set the colors in colors and colors (night) and even try to set Color.WHITE in my code.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
     xMark.setColorFilter(new BlendModeColorFilter(Color.WHITE, BlendMode.SRC_ATOP));
} else {
     xMark.setColorFilter(Color.WHITE, PorterDuff.Mode.MULTIPLY);
}

How can I get Android 10 to use the color I want even in dark mode?


Solution

  • Try calling setForceDarkAllowed(false) on the views you want to remain the same when dark mode is enabled. See the docs