10

I'm facing a weird issue where I'm setting the background of a TextView to @android:color/holo_blue_bright, expecting it to be bright blue, only to find that it's some kind of bright green on a device.

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 (just the relevant line)

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

Above settings produce this. Each message is a TextView

enter image description here

I thought maybe it was because my device displays colors differently or something, so I tried some more holo colors, but they all look exactly as they should

@android:color/holo_green_light gives

enter image description here

@android:color/holo_green_dark gives

enter image description here

Even @android:color/holo_orange_light and @android:color/holo_purple look OK

enter image description here

enter image description here

except for the blue ones:

@android:color/holo_blue_light gives

enter image description here

@android:color/holo_blue_dark gives

enter image description here

All blue appear as similar, but not exactly the same tints of green. Also not the same tint of green as holo_green_light or holo_green_dark.

I thought what is this? Everything looks good, but not blue? and went to check what the HEX of holo_blue_bright is and I found it here (it's #FF00DDFF).
So I tried to use that HEX values directly, instead of using the predefined holo color.

enter image description here

Android studio (v1.2) tells me they are exactly the same color, as I expected.

However, when I then changed

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

to

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

to use #FF00DDFF as color, I got this

enter image description here

Which is exactly what I expected to see when I was using holo_blue_bright! Which should makes sense, considering they're the same color.

I'm stumped. What is going on here, what am I missing? Why do 2 supposedly equal color codes produce different results, and why are all the other holo colors looking normal?


Device info:

OnePlus One
Model A0001
Running Cyanogen OS v11.0-XNPH05Q / kernel 3.4.0-cyanogenmod-gc73a4ec build 04
Running Android 4.4.4

Community
  • 1
  • 1
Tim
  • 41,901
  • 18
  • 127
  • 145
  • wow, and you're seeing the same results on multiple devices and OS versions? – CSmith Apr 10 '15 at 17:36
  • Sadly I have only one device to test on, it's Android 4.4.4 – Tim Apr 10 '15 at 17:38
  • It would be interesting to do getResources().getColor(android.R.color.holo_blue_bright); in code and print the hex value, – CSmith Apr 10 '15 at 17:38
  • @CSmith It gives me `ff8bc34a`, which looks like the kind of green I'm seeing. Why does Android Studio tell me it's `ff00ddff` then? – Tim Apr 10 '15 at 17:56
  • 1
    if you want 100% control of the colors, using a private resource (as you did) is the best way. Your SDK is correct, the manufacturer of your device has possibly applied their own theme or something(?) – CSmith Apr 10 '15 at 18:03
  • Thanks. At the moment I'm more interested in why it is happening like it is than how to get the color right :-) – Tim Apr 10 '15 at 18:05
  • I smell a ROM-Bug here - can you test with an emulator? – ligi Apr 13 '15 at 16:51
  • Emulator shows the right bright blue color (tested with Nexus 5.0.1 armeabi-v7a) – Tim Apr 13 '15 at 17:45
  • as @CSmith said, it's due to manufacturer customization – Kai Apr 14 '15 at 02:17
  • I added the device info, as that seems to play a role – Tim Apr 14 '15 at 08:10
  • This is not really a programming question, more a bug report like thing. @TimCastelijns you already know how to resolve the issue right? – Rolf ツ Apr 14 '15 at 10:18
  • 1
    I know that now, but I had no clue what was the cause when I asked the question – Tim Apr 14 '15 at 10:20

2 Answers2

6

The hexcode for holo_blue_bright in the standard Android 4.4.4 is ff00ddff (Source).

The green color that you get is actually the value of user_icon_6, which is described as "light green 500" (Source).

It looks like the manufacturer of your device customized the color palette by replacing the default values with other colors (intentional or not). This means that holo_blue_bright is defined like this in your customized Android version:

<color name="holo_blue_bright">#ff8bc34a</color>


Now that you provided device information, I looked up the source of CM11. The color defined is ff00ddff, which is correct. However, OnePlus develops their own version of Cyanogen OS, so they may have changed the values for the colors. Sadly, I couldn't find the source code for CM11-XNPH05Q, so I can only guess.

I suggest you to ask OnePlus directly about this issue.

Manuel Allenspach
  • 12,467
  • 14
  • 54
  • 76
  • Interesting. OnePlus is rolling out Cyanogen 12 as of today, it might just be fixed with that then, right? – Tim Apr 14 '15 at 10:51
  • @TimCastelijns I would wait for the update and check the issue again. Maybe they fixed the bug (if it is not intentional), otherwise you can contact them about the problem. – Manuel Allenspach Apr 14 '15 at 11:00
  • 1
    You were right. It is a custom override in cyanogen's Lush theme. I still saw it after I updated to cyanogen 12 but when I was trying new themes I noticed the color was bright blue for every theme, but not for Lush – Tim Apr 19 '15 at 11:35
1

From your comment above

@CSmith It gives me ff8bc34a, which looks like the kind of green I'm seeing. Why does Android Studio tell me it's ff00ddff then?

it is pretty clear that the manufacturer has changed the color on the device. Android Studio gives you the color value from the official android resources in the SDK.

Try your app in an emulator with e.g. Nexus 5. I bet the color will be correct there.

Ridcully
  • 23,362
  • 7
  • 71
  • 86