Draw compound drawable outside EditText background - android

I'm trying to create an EditText with custom background, and a compound drawable to the left, but outside the background (currently it's appearing overlapped to the background); something like this.-
Is this possible?

If your background is the white box - then no, it's not possible to draw outside of the TextView's bounds.
Although you can use a compound background, set the orange colour with the white box inside of it as your TextView's background, then you'll be able to set the mailbox as the left drawable of your TextView.

Related

How to replace color by another on ImageView in Android?

I would like to change (map) white color to blue color. How can I do this on ImageView in Android? I tried setColorFilter by PorterDuff / LightingColorFilter / ColorMatrixColorFilter but I can't figure out how to set it up. There is a transparent background around the image.
Try to use Background Tint color function in xml or java code.
or
I would suggest another way. Take on frame layout and place view and then image view.
white portion in image should be transparent use PNG image.
and you can give color to base view color which ever you want.

Change color of a view dynamically depends on what color of background the view is in

In Android, is there a way to dynamically change the color of the view depending on what kind of background it is in?
For example, if I have a floating TextView with a white text color on a ListView with a black background, the text color will be visible clearly. However, as I scroll down, if the next section of ListView has a white background the texts in the TextView won't be visible anymore since it is white on white.
Is there any way in Android to change the text color of this TextView as it reaches the background with similar/same color?
Well, it depends on the type of background.
If you are talking about a background as in a view(linearlayout, surfaceview, etc) wit ha color, you have to get the position the textview has on the screen, and set a color based on the background color at that point. But it depends on the type of color. A bitmap allows you to get a specific pixel:
bmp.getPixel(x, y);
And then you can determine the color based on that.
However, with a SurfaceView it becomes harder because there is no native method for that.
Further, a gradient-filled background makes it harder to get at a particular point. But if you use a view and have set the backgroundcolor, you can:
if (view.getBackground() == Color.RED){//View = the view with a background set using setBackground or android:background="#color or #drawable or whatever"
tv.setTextColor(Color.WHITE); //then you adjsut the textview color
}
Please be aware that the above example only works if the view has a background defined as android:background or setBackground and there is a color. When you use a bitmap, you can get the pixel and the color based on that pixel
not hard stuff
if view.getBackground() == .RED{
yourStaff.text.setTextColor(Color.WHITE);
}

How to make opacity of view with transparent, infliction, subtraction

How to make background opacity of the View (for ex. EditField )with transparent, infliction, subtraction "Screen" like it is in Photoshop?
I know if I set background to "#android:color/transparent" for EditField then white background will be visible, but not main backgrounf of the layout
I need to implement this one:
You can't do it simply.. not by any code.. the only way to do that is to get a drawable .png image(you need photoshop to create it) that has this shape(semi tranaparent on the frame ans fully transparent inthe center with rounded corners).. make it with small width .. and use 9patch tool for stretching (so you can get flexible width)...

setBackgroundColor() and setBackground() are mutually exclusive in android

I'm trying to make a circle of one color on a background of another.
background = new ShapeDrawable(new OvalShape());
background.getPaint().setColor(main.getResources().getColor(R.color.XXX));
view.SetBackground(background);
will work for the colored circle, and
view.setBackgroundColor(getResources().getColor(R.color.XXX));
will work for the background, but they're mutually exclusive. It just ends up with what I did last. Is there a way to make the circle on another overlapping view or something like that?
setBackgroundColor() is basically a short cut for changing the view's background to a colour drawable.
To do what you want you could try one of the 2 things described below:
Put a view in a FrameLayout, set the background colour in the FrameLayout, and put the shape in the view.
You could also try to use ImageView, which can have a background and another drawable with setImageDrawable() method.

Background size getting changed

I'm changing Background color of a button programmatically as below
Button button =(Button)findViewById(R.id.one);
button.setBackgroundColor(0xFFFF0000);
But after this the size of button getting increased.. Im using relative layout in UI.
Default button background drawable has some kind of margins. These margins are just transparent pixels on the sides of the image. When you set background color for a button these margins disappear because the whole rectangle of the button is filled with the color.

Categories

Resources