Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
154 views
in Technique[技术] by (71.8m points)

Weird Android colour behaviour when changing gaddle's appId

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...