0

I'm getting a weird colour behaviour when changing the application id (xxxx.yyyyyy) in the graddle file to another thing (xxxx.yyyyyy.zzzzz). Strangely this does not happen on the emulator only on the mobile device.

Here's how I'm setting the color to the drawable:

                    View viw = (View) main.findViewWithTag(R.id.viw);
                    Drawable dwl = DrawableCompat.wrap(viw.getBackground());

                    int backColor = getResources().getColor(R.color.Teal);
                    int foreColor = getResources().getColor(R.color.Black);
                    if (voltage < 1)
                        backColor = getResources().getColor(R.color.MediumDarkGrey);
                    else if (min != avg && value == min)
                        backColor = getResources().getColor(R.color.LightRed);
                    else if (min != avg && value == max)
                        backColor = getResources().getColor(R.color.LightBlue);
                    else if (value == avg)
                        backColor = getResources().getColor(R.color.LightOrange);

                    // set color
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
                        DrawableCompat.setTint(dwl, backColor);
                    else
                        DrawableCompat.setTint(dwl.mutate(), backColor);

Here's the color file:

<!-- colors -->
<color name="Black">#ff000000</color>
<color name="MediumDarkGrey">#ff3e3e3e</color>
<color name="Teal">#ff008080</color>
<color name="LightBlue">#ff89bff8</color>
<color name="LightOrange">#fffecb4c</color>
<color name="LightRed">#ffd68080</color>

Here's what it looks like on the device with application id xxx.yyy matching the package name:

https://i.stack.imgur.com/YCHm4.jpg

Here's what it looks like on the device if I change the application id to xxx.yyy.zzz:

https://i.stack.imgur.com/wEGTo.jpg

I need to change the application id because I'm uploading two versions of the same app which need to have different app ids in the playstore.

MakoShark2
  • 25
  • 4
  • OK, just found it's related to the dark theme being switched on. If I set it off colours display as it should be. Still don't understand why this relates by changing the app id. Is there any way to prevent this colour change when in dark mode? – MakoShark2 Jan 12 '21 at 11:28

1 Answers1

0

OK, found the answer here:

How to disable night mode in my application even if night mode is enable in android 9.0 (pie)?

What worked for me:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
       <item name="android:forceDarkAllowed" tools:targetApi="q">false</item>
</style>

Still not sure why changing the app id triggered the dark theme colours change on some drawables...

MakoShark2
  • 25
  • 4