We have a TextView containing a drawable-left and drawable-right from app resources. On some devices like
Sony Xperia L running Android 4.1.2,
Samsung Galaxy Young or
Samsung Galaxy SII
we are facing a strange problem. The drawable will be shown translucent/transparent. On other devices like
Samsung Galaxy S4 (4.4.2) or
HTC ONE V (4.0.3)
the drawable will be shown correctly.
This is a cutout of the Layout definition:
<TextView
android:id="#+id/button_current_warnings"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="3dp"
android:gravity="center_vertical"
android:background="#drawable/selector_classic_list_item"
android:layout_gravity="center_vertical"
android:drawablePadding="8dp"
android:drawableLeft="#drawable/ic_classic_current_warning_white"
android:drawableRight="#drawable/ic_classic_row_arrow"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:maxLines="2"
android:ellipsize="end"
android:text="#string/current_warnings"
android:textSize="?attr/warningGermanyBoxTextSize"
android:textColor="?attr/itemFavoriteTitleTextColor"/>
On the HTC One V device this layout looks pretty nice:
On the Sony Xperia L the layout is broken, due to the transparency of the imageview drawables. Both drawables are only shown a little bit:
Furthermore, if we change the drawable to a different one the result is nice on both devices:
HTC:
Sony:
Additionally I attached the two drawables used for my current tests (they are both white-colored, because of this you will not see anything here):
Wrong displayed drawable:
Correct displayed drawable:
Does anyone face the same problem or has any hints for us?
Update: In my code, I only set an ClickListener on this TextView:
buttonGermany = returnView.findViewById(R.id.button_current_warnings);
buttonGermany.setVisibility(View.VISIBLE);
buttonGermany.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// Do something
}
});
I only encountered this problem on Android 4.1.2 (Jelly Bean) devices. The problem with the translucent presentation of the icons has something to do with caching of drawables in 4.1.2. In my case, I used the wrong ic_classic_current_warning_white-drawable in a drawable-selector, too:
<selector xmlns:android="schemas.android.com/apk/res/android"; android:exitFadeDuration="#android:integer/config_mediumAnimTime">
<item android:state_pressed="false" android:state_focused="true" android:drawable="#drawable/ic_classic_current_warning_white"/>
<item android:state_pressed="true" android:drawable="#drawable/ic_classic_current_warning_white"/>
<item android:drawable="#drawable/ic_classic_current_warning_black"/>
</selector>
This selector was used on a button in previous activity. If I touched this button, the above view appears. By using the android:exitFadeDuration the ic_classic_current_warning_white-drawable was faded out after touching my button. But it seems to be that the drawable cache holds a reference to ic_classic_current_warning_white-drawable with an alpha-value lower than 100%, when the new activity was opened. If I used this drawable again in next view, it was not displayed with 100% alpha, but with the alpha-value when leaving the previous activity.
My current solution is simply to duplicate the drawable ic_classic_current_warning_white. One will be used for the selector. The other copy will be used for "static" purposes.
Related
Here is the XML code for the RadioButton.
<androidx.appcompat.widget.AppCompatRadioButton
android:buttonTint="#android:color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layoutDirection="rtl"
android:text="#string/largest_discount"
android:textAllCaps="true" />
I haven't added any custom icons/button for this RadioButton. Using the default colour and style of the RadioButton. But the icon looks too tiny/small of the RadioButton in Tablet, it looks normal and decent in Mobile device. Here is the attached image. The left one is the Tablet and the right side is a Mobile device. Clearly seen that Tablet icon is too small.
Do let me know what's wrong here. Any help would be appreciated.
I have a drawable which I am using in some scrolling fragment views. This is an image which should be sticky at the bottom of the page, should not scroll with the scroll view and should not stretch.
The drawable:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#drawable/ic_emptystate_buildings"
android:gravity="bottom|center_horizontal" />
</layer-list>
Setting this drawable as background like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg_buildings_grey"
android:orientation="vertical">
works exactly as I want on newer devices, but when I tried on a Samsung S4 with Android 5.0.1, the drawable background streches all the way to the top. The image ('ic_emptystate_buildings' - an imported vector drawable) is only maybe 100dp tall and should not be stretched and should stick to the bottom.
The reason I did not create an ImageView was because its the background of a ScrollView and the XML got messy when I tried to 'hack' it to work. I also want this behaviour in multiple views, so this solution seemed the best because of no duplicate code and simple, clean XML.
Does anyone know why its not working on older versions, and perfectly on newer? And more importantly; is there any nice way to fix this?
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.
I've got an ordinary TextView working correctly on all phones except on certain Samsung devices (Galaxy S2 and S3 for the moment, according to user feedback) and only when using the Helvetica S font (other pre-installed Samsung fonts work correctly).
The problem is that the text gets clipped a bit on the right, instead of wrapping correctly. I still cannot post images, but the issue is the same that happens in this question: Android text gets clipped on some devices (and with the difference that I'm not using Hindi fonts).
This is my TextView and its layout:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingTop="24dp"
android:paddingBottom="32dp"
android:paddingLeft="#dimen/general_padding_sides"
android:paddingRight="#dimen/general_padding_sides"
>
<TextView
android:id="#+id/help_01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="#dimen/help_text_size"
android:fontFamily="sans-serif-light"
android:textColor="#android:color/black"
/>
I tried setting clipToPadding to false on the layout to see if the clipped text could be seen, but the text gets clipped the same way, and I can't make any tests in situ as I don't have any Samsung test device yet (I depend on user feedback).
The thing is I couldn't find any other reference to this problem apart from the question linked above, but if there is a bug with Helvetica S in Samsung devices, I guess someone else should have faced this problem before.
Has anyone encountered this problem? Is there any xml property that I am missing and could prevent this behavior or is this just a Samsung bug?
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.