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.
Related
I have downloaded Google and Facebook 9-patch button files and added them to my app.
It all seemed surprisingly straightforward, as it seemed to work just fine with just setting button background to the 9-patch file and setting some text. Here is the result:
The thing is, when I previewed my app on device with Android 4.0 and 4.4, this is the result:
What can be done, to make the buttons in Android 4 look like the ones in Android 5?
The reason for the buttons displaying wrong could be that the content area in the 9-patch file is wrong. You could try to open the files with the draw9patch tool, that is describe here. Then you can adjust the content area by adding to or removing from the black bars on the right and bottom.
Alternatively you could try adjusting the padding of your buttons
I have actually found a solution.
I used style="?android:attr/borderlessButtonStyle" to get rid of borders. For some reasons, it overriden the padding for buttons in version 4.
Once I changed it to style="#style/Widget.AppCompat.Button.Borderless" everything worked just fine.
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
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.
I just made a nine-patch
it is saved like border.9.png from the draw 9 patch tool.
in my android layout editor, it shows up like it is going to be a proper 9 patch graphic, stretched out yet not pixelated.
yet on a real device, it just shows a giant stretched image, with the 9patch guides seen, it looks really bad
whats going on??? and how do I fix it
my xml:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/border"
android:orientation="vertical"
android:padding="35dip" >
I just had the same issue : everything worked fine in Eclipse but all where streched on the device.
I solved it by opening the PNG in the Draw 9-patch tool.
Just open the png and save it et voila !
You can find all the necessary information how to create a 9.patch here
Your background should be like this
Note: the markers to the bottom and right need to be drawn as complete lines, not single dots.
Edit
Seems that uploading the 9.patch here becomes altered, and cannot be used as a 9.patch anymore. You can download the functional version from here
This looks like invalid 9.ptach file to me. There should be solid regions at the bottom and on the right side.
As a last resort, whenever you're having a tough time getting a 9 patch to be recognized as such, I find it's always best to just make a BRAND NEW image file in your imaging software, copy all except the 4 1-pixel borders of your original image, then paste into your new image file. Sometimes no matter how much you delete away the 4 edges, the device/emulator still can't recognize it as a 9-patch, even though (and this should probably be of concern to the Android SDK dev team) it's a perfectly fine 9-patch in Eclipse's Graphical Layout.
Also note, black lines on the right and bottom edges are optional. They specify "padding", in particular the region where the content (the child of the parent with the 9-patch background) fits.
It took me some hours to figure out, why my nine patch didn't render right.
The reason was quite simple. My nine patch image was stored under:
/res/drawable
instead of
/res/drawable-xxx
I recently downloaded an app from the market called WunderList and it has this neat effect on a Edit Text for transparency
I am trying to recreating the same effect for one of my applications but I am not really getting anywhere. I initially thought it is just transparency but I was wrong. Now I have put an image with shadow as the EditText's BG an trying to set it's alpha. I am not sure If I am on the right path. I would appreciate any guidance on this.
I got this done through a custom 9patch image. Here's a sample result.
It's not close but I am getting closer.
That's actually the way we do it.
We use a 9patch PNG with transparency.