蓝色全息色在设备上呈现为绿色

10
我遇到了一个奇怪的问题,我将TextView的背景设置为@android:color/holo_blue_bright,期望它是明亮的蓝色,但在设备上却发现它是一种明亮的绿色XML
<TextView
    android:id="@+id/tv_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:background="@drawable/chat_bubble"
    android:maxWidth="300dp"
    android:padding="5dp"
    android:singleLine="false"
    android:textSize="16sp" />

@drawable/chat_bubble

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/chat_bubble_background" />

    <corners android:radius="5dp" />
</shape>

colors.xml(仅相关行)

<color name="chat_bubble_background">@android:color/holo_blue_bright</color>

以上设置将生成此结果。每个消息都是一个TextView。

enter image description here

我想也许是因为我的设备显示颜色有所不同之类的原因,所以我尝试了一些其他的霍洛颜色,但它们看起来都正如它们应该看起来的那样。 @android:color/holo_green_light 显示:

enter image description here

@android:color/holo_green_dark 提供

enter image description here

即使是@android:color/holo_orange_light@android:color/holo_purple看起来也不错

enter image description here

enter image description here

除了蓝色以外: @android:color/holo_blue_light 给出

enter image description here

@android:color/holo_blue_dark 给出

enter image description here

所有的蓝色看起来都很相似,但并不完全是相同的绿色色调。也不是与holo_green_lightholo_green_dark相同的绿色色调。
我想:“这是什么?一切看起来都很好,但不是蓝色?”然后我去查看holo_blue_bright的HEX是什么,我在这里找到了它(它是#FF00DDFF)。所以我尝试直接使用这个HEX值,而不是使用预定义的holo颜色。

enter image description here

Android Studio(v1.2)告诉我它们的颜色完全相同,正如我所预期的那样。然而,当我接着改变时...
<solid android:color="@color/chat_bubble_background" />

<solid android:color="@color/chat_bubble_background2" />

要使用#FF00DDFF作为颜色,我得到了这个

enter image description here

这正是我在使用“holo_blue_bright”时期望看到的!考虑到它们是同一种颜色,这应该是有道理的。
我被难住了。这里发生了什么,我错过了什么?为什么两个看起来相等的颜色代码会产生不同的结果,而所有其他的holo颜色看起来都很正常?

设备信息:

OnePlus One
型号 A0001
运行 Cyanogen OS v11.0-XNPH05Q / 内核版本 3.4.0-cyanogenmod-gc73a4ec build 04
运行 Android 4.4.4


很遗憾,我只有一台设备可以测试,它是Android 4.4.4。 - Tim
@CSmith 它给了我 ff8bc34a,看起来像是我看到的那种绿色。为什么 Android Studio 告诉我它是 ff00ddff 呢? - Tim
1
如果您想要100%控制颜色,使用私有资源(就像您所做的那样)是最好的方法。您的SDK是正确的,您设备的制造商可能已经应用了自己的主题或其他东西。 - CSmith
谢谢。目前我更关心的是为什么会发生这种情况,而不是如何正确设置颜色 :-) - Tim
1
我现在知道了,但当我提出问题时,我不知道原因是什么。 - Tim
显示剩余7条评论
2个回答

6
在标准的Android 4.4.4中,holo_blue_bright的十六进制代码是ff00ddff来源)。
你看到的绿色实际上是user_icon_6的值,被描述为“浅绿500”(来源)。
看起来你设备的制造商通过替换默认值来定制了颜色板(无论是有意还是无意)。这意味着在你的定制版Android中,holo_blue_bright被定义为以下内容:
<color name="holo_blue_bright">#ff8bc34a</color>

现在您提供了设备信息,我查找了CM11的源代码。定义的颜色为ff00ddff这是正确的。然而,OnePlus开发了他们自己的Cyanogen OS版本,所以他们可能已经改变了颜色的值。不幸的是,我找不到CM11-XNPH05Q的源代码,所以我只能猜测。

我建议您直接向OnePlus询问这个问题。


有趣。OnePlus今天开始推出Cyanogen 12,也许问题会在这个版本中得到修复,对吧? - Tim
@TimCastelijns 我建议你等待更新并再次检查问题。也许他们已经修复了这个错误(如果不是故意的),否则你可以联系他们解决这个问题。 - Manuel Allenspach
1
你是对的。这是Cyanogen Lush主题中的自定义覆盖。我在更新到Cyanogen 12后仍然看到它,但当我尝试新主题时,我注意到每个主题的颜色都是明亮的蓝色,但Lush主题不是。 - Tim

1

从您上面的评论中

@CSmith 它给了我ff8bc34a,看起来像我看到的那种绿色。为什么Android Studio告诉我是ff00ddff?

很明显制造商已经在设备上更改了颜色。 Android Studio会从SDK中的官方安卓资源中获取颜色值。

在模拟器中尝试您的应用程序,例如Nexus 5。我敢打赌颜色将在那里正确。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接