【问题标题】:Weird Android colour behaviour when changing gaddle's appId更改 gaddle 的 appId 时出现奇怪的 Android 颜色行为
【发布时间】:2021-01-12 10:56:02
【问题描述】:

将 graddle 文件中的应用程序 ID (xxxx.yyyyyy) 更改为另一个东西 (xxxx.yyyyyy.zzzzz) 时,我得到了一种奇怪的颜色行为。 奇怪的是,这不会仅在移动设备上的模拟器上发生。

以下是我为可绘制对象设置颜色的方法:

                    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);

这是颜色文件:

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

这是应用程序 id xxx.yyy 与包名称匹配的设备上的样子:

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

如果我将应用程序 ID 更改为 xxx.yyy.zzz,设备上的效果如下:

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

我需要更改应用程序 ID,因为我正在上传同一应用程序的两个版本,它们需要在 Playstore 中具有不同的应用程序 ID。

【问题讨论】:

  • 好的,刚刚发现它与打开的黑暗主题有关。如果我将其设置为应显示的颜色。仍然不明白为什么这与更改应用程序 ID 相关。有什么办法可以防止在深色模式下发生这种颜色变化?

标签: android android-studio colors drawable app-id


【解决方案1】:

好的,在这里找到答案:

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

什么对我有用:

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

仍然不确定为什么更改应用 ID 会触发某些可绘制对象上的深色主题颜色更改...

【讨论】:

    猜你喜欢
    • 2013-09-29
    • 1970-01-01
    • 2013-01-06
    • 2015-02-02
    • 1970-01-01
    • 2013-05-17
    • 2021-11-16
    • 1970-01-01
    • 2013-12-31
    相关资源
    最近更新 更多