Android 9-patch drawable not showing only in some versions - android

I've a very strange problem with a specific 9-patches drawable, only on some devices (works on emulators): it simply does not show. I've tried everything. Renaming the file does not work. Removing the .9 part from the name of the file shows the drawable. Using other 9-patches it works.
The files are expander_close_holo_light.9.png and expander_open_holo_light.9.png from latest sdk.
The image is set in an ImageView with setImageResource. The style of the view has a background Drawable, that becomes blue when touched.
So I know the view is correctly layouted, because touch works even when the image is not shown. I think the problem lies only on the image itself (as I said other 9-patches drawables work).
Any clue?
Thank you,
Ignazio

Related

Android app drawable images (icons) loose colors to white on some devices in Lollipop

When I am adding transparent png icons/images, their color schema changes to "monochrome white", i.e. all the colors but white change to white as on the image:
Most of devices were working well so far, it happens not often.
I am not sure if that's related to the image format, OS version or device, but probably someone already bumped into similar thing.
The images are added as AndroidResource as drawable and have different resolution versions. (I am using Xamarin Android, but not sure if that's related to the issue).
The issue is happening as when the image is added to widgetTab.Layout as menu item as just setting up ImageView.
Any thoughts?

Google Card Style 9-Patch with ListView - Android

I am trying to use the card_background 9-patch that is extracted from the play store apk and I am having trouble getting the 9-Patch to place itself correctly. Here is an image of my emulator running this problem. I am trying to make the typical card view that is used somewhat commonly now but this is just one of the problems I cannot work out how to fix.
My 9-Patch card_background:
I am also pretty sure the 9-Patch is setup incorrectly as according to the 9-Patch tool in /sdk/tools the entire two areas that I am using are both bad patches but I don't know what that means so I hope one of you can help to fix this.
I modified your image, I think this works:
Your 9-patch image stretches all the white/border correctly, but it has nothing but transparency at the bottom. If you want a gray shadowy area beneath it, you need to draw it there, below the white. Just make sure you don't extend the black stretch-bar down to it, or it will stretch as well.
Go into the sdk's nine-patch editor tool after you extract the png's from the apk and put them in their respective drawable folders. The tool can either be the one inside the /tools or, even better, the direct editor in Android Studio.
Modify the stretch regions for each image to your liking until it looks like an actual card. I had the same problem, until I went back and redid the stretch regions. For some reason, the png extracted from the apk didn't save the stretch regions when extracted.
You should have a shadow automatically appear from the given images, you DO NOT need to draw it yourself. Just make sure you don't include the corners and the shadow in the stretch region. And give a little bit of slack too.

Android: 9-patch png is treated like a normal png

I've made this 9-patch png and added it to the res/drawable folder:
It works nice in the example eclipse shows:
But on the emulator it looks messed up:
Why is this happening and how can I fix this?
EDIT: The border on which I've placed the black dots is white, not transparent. Not sure if that's got anything to do with it...
This probably happens because you have a small mistake with the black pixels you have set.
Try to re-cut the edges of the picture and to add the black pixels all over again.
I had this problem too once and this helped me.
if the border is white then this is your problem it has to be pure black or nothing at all.
UPDATE: Try this image:
It seems you are not saved your image with .9.png
In order to make it work do like this
save your image in the following format in your drawable folder
yourimage.9.png (not png format of your image)
Check this reference draw 9 patch
The Android SDK contains a 9-patch editing tool (draw9patch.bat) that can help you to produce and/or validate 9-patch images. Without it, it is very easy to make a mistake in defining your border.
The one-pixel border should be transparent except for the black pixels that define the various parts of the image to be treated differently during scaling.

working with android 9 patch file not working

I have been trying to change the color of the gray that surrounds my custom tabs, I have tried looking for the answer on YouTube:
http://www.youtube.com/watch?v=IfrXE2R2nqM
http://www.youtube.com/watch?v=XMWlRXfKgtY
This helped me understand the process of 9-patch files but I must be doing something wrong for this not to work.
What I have tried doing so far:
In my project I see in the "Package Explorer" I see Android 4.1, which is in ...android-sdk/platforms/android-16. I opened that with winrar, went into res/drawable-mdpi and just to see if anything would change I replaced "tab_selected.9.png" and "tab_selected_v4.9.png" with the image of "tab_pressed.9.png". I then tried to compile my project just to see the same gray for the background of my tab buttons.
The current android project I am working on I placed the changed "tab_selected.9.png" and "tab_selected_v4.9.png" inside of my drawables folder and tried running it just to see the same thing.
Does anyone know what I am doing wrong, am I not compiling something or do I need to mess with different .9.png files? Or does anyone have a simple process just to change the gray color of these tabs? I guess the quick answer for me here is what would I have to do to get the image of "tab_pressed.9.png" to replace "tab_selected.9.png"
EDIT:
tab_selected.9.png
tab_pressed.9.png
Make sure the only pixels in the border are the 9-patch ones, either black (#f000 in ARGB) or fully transparent (#0000).
It's a normal to left some pixels with some transparency on those pixels that gets unnoticed at simple view.
This is a little tricky. Sometimes the stuff like the grey can creep in from the underlying Android layer. Sometimes things like tabhost have views that have to be overridden. I remember having to maek a selector drawable in XML to get the tabhost to work with custom items.

png image showing up with grey background in android

I have some png image buttons that I use in my app. But they are showing up with grey backgrounds on my page. Does android always show a grey background for a transparent one? Is there a work around?
This is how it showed before.
This is how it shows after I made #FF000000 edits
This is how I want it to show.
EDIT:
Error when I use #FF: Color value not valid -- must be #rgb, #argb, #rrggbb, or #aarrggbb (at 'background' with value '#FF'). main.xml
#android:color/transparent. Phoenixblade9 was close.
If the image is transparent, there should be nothing shown behind the image.
The default colors vary from distribution to distribution. The color scheme/theme for an HTC phone will be different than from a Motorola phone, or the emulator.
If you want to ensure that a view has a transparent background, set the following in your XML code for that view:
android:background="#android:color/transparent"
This should ensure the background is completely transparent.
The code line in the ImageView or ImageButton in the XML file is actually:
android:background="#android:color/transparent"
I am writing this to help someone who is not familiar with the platform and won't connect the two answers above.
I found this happens if you have android:src="#drawable/mypngimage" in your xml file. Instead if you use background then the gray area goes away and it behaves as expected. android:background="#drawable/mypngimage"
Please check whether your image is 32 bit depth or not. After that insert this code in your image view: android:background="#android:color/transparent".
To make your image transparent open Adobe Photoshop or Illustrator, open file (i.e. your image) and click file and click to export - save as web (legacy), tick transparent and save it.
Also you can use #50FFFFFF (aarrggbb). in this format, aa is alpha channel to be transparency frequency. So If you use above color, you get a 50% transparent white background.

Categories

Resources