Blue Holo colors appear green on device - android

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
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
#android:color/holo_green_dark gives
Even #android:color/holo_orange_light and #android:color/holo_purple look OK
except for the blue ones:
#android:color/holo_blue_light gives
#android:color/holo_blue_dark gives
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.
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
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

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.

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.

Related

Developing Material Design homescreen-widgets in Android

Ok, so I'm working on a very simple Android homescreen widget that fetches the latest Image from an imageboard and displays it in a imageview.
I'd like to have the option to Style this widget, to be in keeping with Googles Material design guidelines, however, I hit the following problem whilst developing and testing on my Nexus 5 running Lollipop 5.1 -
I can't seem to use a cardview in a widget. It gives me a class not found exception however I do not get such exceptions previewing the layout and my gradle has the right dependancies so I suspect it is more to do with widget compatibility?
So I did some further reading and on the Google API page about widgets it has a very specific list of views that widgets support, which did not, to my surprise include cardviews. So I've gone back to my plain old Imageview
I guess my question then sits with, how would I get this imageview to look like a material design card? EG, rounded corners, the subtle 3d effect, drop shadow, ETC. I do not wish to give the imageview a border, the edge of the image should extend to the edges and get clipped by the rounded corners.
I have tried by simply setting the style of the Imageview to be that of a cardview, but that seems to have done absolutely nada :)
Anyone has some ideas? Thank you!
you might want to have a look at the source of the google i/o app : https://github.com/google/iosched/blob/master/android/src/main/res/layout/widget.xml
This is from a long time ago, but it's very doable to make a simple card background in XML.
The way to do this is to create an cardview-esque .xml file in your drawables app resources folder.
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/white" />
<corners android:radius="4dp" />
</shape>
and set the background view of your Widget's XML layout as
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/widget_card_background"
android:orientation="vertical">
<.../>
</LinearLayout>
You are correct in that CardView is not an available View type for Android Widgets, but this should create the functionality you were looking for 2 years ago

Widget changed appearance with 4.4

I have a very basic widget with two buttons in a layout. They look like standard android buttons, but with the 4.4 update the buttons now appear as a dark grey instead of light grey. They remain normal in previous versions of android. Does anyone have any idea of why this is happening and how I can fix this?
Thanks!
Button xml:
<Button
android:id="#+id/button_widget_newshift"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="#string/new_shift_split"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#101010"
android:textSize="#dimen/widget_text" />
I don't have an answer (and I don't have enough of a reputation to post a comment). I have the same problem, although I'm creating my buttons in code. They work on devices prior to 4.4, but are dark grey and borderless on my Nexus with 4.4 and a 4.4 emulator.
I understand that 4.4 changed drawables to tone down touch feedback (see http://developer.android.com/design/patterns/new.html). Perhaps, in the process, a button style or drawable got misplaced. If so, a solution/kludge might be to copy working resources from the SDK into your project and call setBackgroundResource() to them. I haven't tried this; I'm hoping someone can come up with something more elegant and definitive.

What could cause wrong EditText background color on Nook HD+ device?

I have had two reports from Nook HD+ users that my android app using a Holo Dark theme does not show EditText colors correct: they appear with white text on white background, making it impossible to read. I have applied no custom styling and the EditText layout looks like this:
<requestFocus />
</EditText>
Any idea what is causing this and if there are any work arounds? Could it be that the Nook does not support the Holo Dark them correctly? THanks in advance,

Checkbox with State List Drawable taking up more space than the graphics call for

I've got a checkbox with a state list drawable and my own graphics (it's for a game). The built-in checkbox graphics are apparently 72x72, and my graphics are 72 high, but only 27 wide.
Snippet of my main.xml layout:
<CheckBox android:id="#+id/r_diff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/reset"
android:layout_alignParentBottom="true"
android:onClick="onClickRDiff"
android:button="#drawable/console_select_switch" />
And here's my console_select_switch.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector android:constantSize="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="#drawable/consw_cntr" /> <!-- pressed -->
<item android:state_checked="true"
android:drawable="#drawable/consw_down" /> <!-- checked -->
<item android:drawable="#drawable/consw_up" /> <!-- default -->
</selector>
Now, when I run the program, my graphics do show up, and they do work, BUT they take up as much width as the original square 72 pixel graphic. I've even tried setting
android:width="27px"
in the selector item statements, also without effect. I even tried turning constantSize to 'false', but that had no effect.
I'm unclear what the heck I'm doing wrong - my understanding is that wrap_content should cause it to be 'as wide as it needs to be', so I assumed that it would just work. Interestingly, when I used some of the same graphics as android:background in a regular button, it works fine.
Edit: the API level on my project is set to 7 (Android 2.1), if that has any relevance (looking at the docs, I think all of what I'm using has been in place for a long time, so I doubt it).
Edit: I just played with setting the text on this control (I tried various values including an empty string for the android:text parameter) and the text is drawing to the right of the area that the checkbox is consuming (not the area actually occupied by the graphic). So clearly something thinks that this checkbox is 72 pixels wide, when it's really 27.
OK, I finally figured it out. This link leads to a detailed look at changing the appearance of the checkbox, wherein I figured out that the default background is in fact an image (it's a 9-patch, to accommodate the text). The underlying background image turns out to e 60x60, and was thus the cause of my troubles. I've put a background image of my own in my resources and referenced it from the layout by adding
android:background="#drawable/my_background"
to the checkbox definition in the layout.

How to get favorites star

I would like to add a favorites star like the one in the contacts list on android. Is there any way we can get that star or will I have to write my own? I can't seem to find any standard GUI Elements from android other than the options menu icons. Are there any more that I have not found?
Look at the one the right next to George Anderson. When you click it it turns yellow.
(source: mail2web.com)
The source code to the Contacts application is available online, since Android is open source.
Some poking around in there will lead you to the contact_header.xml file, found in your SDK installation. It indicates that the star is implemented via a CheckBox:
<CheckBox
android:id="#+id/star"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:visibility="gone"
android:contentDescription="#string/description_star"
style="?android:attr/starStyle" />
That, in turn, routes you to an entry in a theme:
<item name="starStyle">#android:style/Widget.CompoundButton.Star</item>
which in turn resolves to:
<style name="Widget.CompoundButton.Star">
<item name="android:background">#android:drawable/btn_star_label_background</item>
<item name="android:button">#android:drawable/btn_star</item>
</style>
So, use those images with a CheckBox, and you should get the same behavior. Those images are also available in your SDK installation.
Some standard android images are available from the android sdk, which you can either browse on your computer on online here. (As CommonsWare said).
I also find this website super handy, as it shows me what each image looks like and tells me the name of the image so I can find it in the android sdk.
#android:drawable/btn_star (this one turns yellow)
#android:drawable/star_off
and variations on those (big, on, off)

Categories

Resources