How to change color in Drawable? - java

I have ImageView in my application, but images in this ImageView have white background. How I can delete this ColorDrawable. I need to replace White to Transparent. How I can do it programmaticaly?

This is probably not as easy to do programmaticaly but it is easy to do in an image editor. I always do it in paint.net. You can download it here: http://www.getpaint.net/download.html
This youtube video describes how to do it: https://youtu.be/cdFpS-AvNCE
It literally takes less than a minute to do and is what I have used on a lot of my projects.

The color you set by ImageView.setBackgroundColor method shows up only where the src image have some transparent pixels or some spaces of ImageView that is not covered by the src image because of scaleType And I'm not sure you want to process images in your code in order to replace back color with transparent color, So the right way to achieve that is to use some Photo Editor softwares to edit images before using in your app.

First, you'll have to remove the background from the original photo using a photo editor like GIMP ,be sure to save the file in an Android supported format that supports transparency (PNG).
Next, inside the XML layout file (or in code), put the drawable view itself inside a FrameLayout.
Finally, call View.setBackgroundColor() on your FrameLayout.

Related

android imageview come from over screen

hi.
I have a problem with android layout.
gif is what designer want I make. and I made things successfully but menu.
png(alpha image) is our menu image. last 40px of height is want to display.
and if user touch that 40px of image is coming down just like gif image shows.
I don't have any idea how can make that. Constraint Layout doesn't support negative value.
ps. png is based on 1080 height resolution. but I will add dynamic resolution calcaulator function, so don't mind about 40px. 40 just mean 'want to display part of imageview'
SOLVED.
make imageview in constraint layout xml and inflate it.
then you can set x,y location programmatically.
I confused it. because when I tried it, It doesn't work. you must know view has relative location.

Android - Setting colour to image

I'm getting stuck at a certain part of my app.
In my app, I have a few icons. The icons are completely white with transparent backgrounds. Is it possible for the user to set the colour of the icons without messing up the transparency? I tried searching a lot, but couldn't come up with anything. Could someone help me out?
Also would it be possible for the user to set custom icons from any folder as per their choice?
Thanks.
Yes it's possible. You have to create bitmap from resource How to set a bitmap from resource, then search bitmap for white pixels and change them to desired color (pix - by pix), then just set result bitmap as button or other layout element bitmap.

Image that has multi clickable zones/surface/area

I want to have an image on the android screen where different parts of the image can be clickable. What I mean is that, If its an image of 3 circles, I want to be able to click each of these circles,
Then I can add different functionalities to each of these clickable circles.
For an instance in this image below I want to be able to click each distinct color. Is it possible to have on-touch-listener and get you the color ? and can it be an image or has to be drawn in Java OR XML ?
I found a really good widget that helps you make any image muli-clickable. They have some good notes on how to use their widget as well.
The widget has a similar approach as Image mapping in html. The good thing about this widget is that the image can be zoomed and it will not lose the coordinates or areas associated to specific clicks.
Here is the link to their website. the guy who made the widget apparently had similar problem and came up with this widget.
Another solution would have been
creating an ImageView containing the png file referenced
making the whole ImageView clickable
setting an OnTouchListener to the ImageView which overrides the onTouch method
check the colors of the image pixel at the touch position
This is often done with an invisible mask image with one color for each zone (see the popular detailed tutorial), but here the image itself has distinct colors for each zone which makes it more interesting.

Android border layout with an EditText overlapping on it

I want to code a layout like the following image in xml in Android.
One approach would be to have a RelativeLayout and make a 9 patch rounded rectangle border image, have it as the background around a layout which has the two blue buttons, and then have and EditText overlapping it, with its background set to a red color.
What could be other approaches?
As I understood your question you want to make series of photos ..like Gallery application
you can do it with more option also.
1)this is gallery type application .
so . you can use this basic code :Android Gallery Application
2)If you want to see all the photos in circle this is also possible..
It depends upon your need ..please write in brief you want more...

Apply 9-patch drawable to Button, keeping default padding

I'm attempting to customise the look of a Button using a 9-patch drawable with no padding defined within in (no pixels on the right or bottom inside the 9-patch editor).
Is there a simple way to apply a 9-patch drawable to a button and maintain the button's default size. For example, when I apply the 9-patch to the Easy button shown below, it is a different size to the other default styled buttons, which share the same layout, except for the 9-patch style.
Mdpi layout:
Hdpi layout:
So basically, is there a way to make the Easy button the same size as Medium and Hard, on both mdpi and hdpi screens, without making a new 9-patch for each density, and working out the correct padding.
Thanks in advance for your help, I can provide more information if required.
Well after some more research it seems that it isn't easily possible to use one 9-patch drawable for all screen densities.
The link below states you need different drawables for each density:
Custom Color Buttons for Android
3.1. Create images 9-patch images for the different colors that you need and put them into drawable-hdpi and drawable-mdpi (yes, you will need two versions if you want your buttons to look good on different devices).
If anyone knows any different though, your help would be much appreciated.

Categories

Resources