Transparent PNG image not looking nice - android

I have an image that has a fairly large shadow around it and its background is transparent. I have saved it as a PNG file from photoshop and am using it in an ImageView through xml. This results in the shadow having a banding effect and just doesn't look nice. Not too sure what to do...

Just add
// set 32 bit window (draw correctly transparent images)
getWindow().getAttributes().format = android.graphics.PixelFormat.RGBA_8888;
in onCreate(...)
http://www.curious-creature.org/2010/12/08/bitmap-quality-banding-and-dithering/

I can't remember what this property was used on, but I think it was an ImageView.
Try using android:dither="true" as part of the ImageView xml declaration and see if that helps.

I can't remember where I read it, but on the developer site somewhere there was this suggestion for fixing gradient banding; it might help with the shadow as well. Right click the effects icon on the layer that has the shadow, and click "Create Layer" to make a separate layer for the shadow. Then apply an "Add Noise..." filter to the layer with the following settings:
(in case the image ever disappears, Amount:0.5%, Uniform, Monochromatic)

Related

Android How to change text color according to background image

On Android, I have a header with a background image (Random image according to API).
On this header I have texts with some data. My text is every time black but sometimes image is black too. So, we can't see the text.
I'm looking for library or snippet for resolve this problem.
Thanks.
You can use the palatte library for this. Please see the following:
https://developer.android.com/reference/android/support/v7/graphics/Palette.html
https://developer.android.com/training/material/palette-colors.html
I encoutered this problem months ago and was not really sure how to approach it. First of all you need to use a Layout where you can put View over View for example Relative or Frame. After that you need to make the ImageView thats behind the TextView to be a little bit Lighter or Darker (like a shade) at the place of your TextView so you can choose a color for your text which will always be readable since the shade will be in contrast with the text. What you can do is put something behind the TextView and the ImageView which will be Light or Dark and make the ImageView a little bit transparent using set.alpha(int) if i remember correctly. So at this point you will have transparent image with a light or dark rectangle behind it. It will be visible that the part where you have the rectangle is darker/lighter. Then you put your TextView there with contrast color to the Rectangle and you will always be able to see it. It is kind of complicated, but it will work. Hope it helps.
I think palatte is not available for android. So glide will be a better option. Link

Layered button with transparent icon in Android

Is it possible to make layered button in Android with transparent icon throgh first layer? It looks tricky, I could make different assets but is it possible to achieve it programmatically? Example below
EDIT: Icon has no background, only border.
Seems easy enough. Save the icon as a .png file, such that anything besides the arrow outline is transparent. Then it's a simple matter of drawing one ImageView on top of another ImageView, depending on what you want.
In order to tint the arrow, use a TintableImageView as described here.

Creating non-traditional shape tooltip in android with border

Hello fellow Android designers,
I am struggling right now to create xml tooltip that would look like the one on this picture:
Unfortunately it seems like a hell of a work. Till now I was only able to create a simple rounded rectangle like that:
Is it actually possible to create such a shape I have presented on the first photo using xml styling or should I try to create it programatically (which will probably take huge amount of time and creating border would be really hard)? Or maybe the simplest solution is the best and I should use partially transparent png image with the shape of my choosing?
Any advice would be much appreciated.
You can draw it using stretchable 9-patch drawable.
You can specify there which parts are fixed (the little knob on the left and corners) and which are stretchable (all other parts)

Draw a gradient filled polygon to use in a selector

I am trying to create a drawable such as this in Android:
I don't think a nine patch will work because there is nowhere that can safety scale vertically. So next I tried a shape drawable but it does not support triangles.
I want to render this image on the fly so there are no artifacts. Also I want to be able to use it in a selector, so I need to be able to represent this image in xml. Maybe I need to extend some class to manually make the shape. If so how do I embed a tag in the xml to tell it where to render? Does anyone know where to start with this or have an example of something similar?
I have read the first 10 pages of hits on stack overflow and google and am not getting anywhere. Thanks very much for any help.
I think a 9-patch would work. For the vertical stretching on the left boundary, fill in the line from top to bottom.

Custom Map markers and custom backgrounds

I am trying to get the images to have transparent backgrounds so the map is not blocked by a square marker with an image in it. What image editor and what settings should I use to get this to work?
I am trying to do some custom backgrounds for buttons and the same problem comes up: I get square corners and a background that does not scale with the buttons.
I think this all part of the same problem: I am not using the right tool with the right settings to create the images. I must be misinterpreting the documentation and examples that talk about a white border around the image and a black line along the top and left side for the expandable button background.
Here's a quick way to reproduce the problem:
Follow the directions to create the MapView program as described on:
http://developer.android.com/resources/tutorials/views/hello-mapview.html
For the icon I first used the image copied from the page:
Next I edited the picture in Microsoft Paint, and cut off the little guy's antennae. I'm not cruel and no real androids were harmed in that experiment. I surrounded the new picture with a pixel thick border of white, copied from the border that was around the rest of the image, and then copied the black that was there as well in the void areas of the image, outside the border.
I saved the image as myandroid.png and copied the file to the layout folder. Pointed the activity to the new pic and ran the program.
The image was displayed with a full square background and shadow, not the android shaped image and shadow that was there when the original image was used.
Custom Button background:
Follow the directions for the Relative Layout example at:
"http://developer.android.com/resources/tutorials/views/hello-relativelayout.html"
Next, I created an image to expand as a background for the button called backbutton.png. It too is surrounded by a white border and black filled on the corners, the top and one side per documentation I found in "Android Programming Tutorials" on page 298.
The background does not expand, nor do the corners round.
I wish I could show you screenies of what I have.
How do you create the images for the custom backgrounds and the images for the custom map markers and buttons? I need to know what image editor to use and the file attributes to set, so the images expand and display with the proper void spaces in them.
Thank you in advance.
You used MSPaint to save the image did you define the transparent color?
should in Image > Attributes
To create custom backgrounds for buttons and other widgets that can change their size at runtime, you should create NinePatch images. The tool you should use is draw9patch and is available with the Android SDK.

Categories

Resources