Android view setBackgroundColor() and night mode

331 views Asked by At

I'm developing an android app and i need to allow user to choose via color picker the list view items's background color. Each listview item is a LinearLayout and i set the background color inside my adapter in this way:

holder.rowLayout.setBackgroundColor(this.backgroundColor!!)

All works perfectly in day mode but when the app switches to night mode i'm experiencing problems with colors.

Let's take this example: in day mode i choose bright green background and it correctly applies to the list:

enter image description here

But when i switch to night mode, colors are the following:

enter image description here

Now, i don't want to disable day\night to all the application. I've all my themes responsive to day\night preference, i just want to avoid dark mode to alter colors of this listview only since it's the user that choose its background color and i don't want Android to alter it.

I've tried to apply older themes to the linear layout and using LinearLayoutCompat without luck. Is there somebody that can help me?

1

There are 1 answers

0
Adri On

try this, on the XML code object input that line:

android:forceDarkAllowed="false"