When I draw text in TextView or fill background color in LinearLayout,
I found something weird which cannot be found in Windows programming.
The background color in the Layout and text color in TextView,
are not a single color, but a mixed color
when I capture the phone screen and see and check the pixel value on the PC.
If I set the text color or as 0xFF1010FF (Blue),
most of the pixels are 0xFF1010FF,
a few of them are 0xFF1010FD or 0xFF1010FE, a slight different color value,
I guess it is for anti-aliasing.
So does Layout Background Color. (1 or 2 value difference for each pixel)
These effect the color looks smoother in android than PC,
but I don't want to fill color like that, but just with exact color value.
Can I make the color with an exact single value?
I tried TextPaint.getPaint().setAntiAlias(false); but it didn't work.
Moreover, I may not be able to use TextPaint for the Layout Background.
This question will be a common issue for most android developers,
so I will be very appreciated for any of your advice.
Thank you.
I tried this, and it worked for me :
TextView textView1 = (TextView) findViewById(R.id.textView1);
textView1.getPaint().setAntiAlias(false);
This effectively disables antialising, so IMO it's not to be done, but if it's what you're looking for, there you go.
Related
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
I want to make in my application some meme - type images.
I've found some fonts, which I can use, but one thing, which is connecting them is, that when I'm changing textColor property for TextView, which is contining text, I'm changing contour of letters, not whole letter color. When I'm changing background color, I'm changing whole TextView field background (and I want it to be transparent). And the problem is, that in letter I can see background image of photo, which is under the letter, which is problem, because photos can have different colors and text could be not visible. Is there any possibility, to change background color, but only for letters? Or it is a job for someone who is working with graphics and fonts?
There is a photo, which is from my app, which is showing problem.
And there, what I'm looking for:
(source: canada.com)
It sounds like what you want is text outline or a text shadow. This question has both of those already answered. Or you could instead use solid font types.
It sounds like you want to change the text colour not the background colour.
The thing is fonts are all defined like small bitmaps, if you change the colour only the opaque bits will be colourised never the bit's which were left transparent.
I think your only option is to change font
I need to change my EditText border colour. I know that there is a way with shapes, setting shape with red boards as EditText's background. But I think that there must be some other and easer way. I searched but didn't found anything. So does anybody knows some other way?
Take one image with border what u like and set that image in edittext background
I have some Text that I sometimes want to have a black outline, and sometimes green. I thought I could accomplish this by having two StrokeFonts, one with black outline, and one with a green outline, and then when I instantiate my Text object I just use the font I want.
The problem is that after that, I ALSO need to set the main color (inside, not stroke) of the font based on other conditions. While my logic works, when I do setColor() the stroke always is black, rendering my first logic useless.
Is there something I'm missing here, or another way to get around this? I have commented out the setColor() calls after I decide which StrokeFont to use and I see the stroke properly, so I know it's getting overwritten with the setColor() call.
Set color multiplies the value of the existing color. So black (value 0) will never change color. But white will become any color you want.
So if you want to make a sprite or text that will assume any color, it has to start out as white.
I think you may still have a problem though, since the stroke of the stroke font is drawn to the same texture as the fill, so that any color adjustment made to the stroke will equally tint the fill.
You're either goiuing to need more Fonts, or choose another way to render them, such as using an outline font and a fill font to that you are actually displaying two Text objects.
Either way, you should be able to find your way if you understand that setColor multiplies the values times the existing value.
I have an app where I am trying to add text shadow to a TextView. The problem is: the shadow is always very thin. I'd like it to be thicker.
I am trying to generate "memes", as some of you might know from the "fun sites" on the internet. My goal is something like this font:
http://d24w6bsrhbeh9d.cloudfront.net/photo/4324188_460s.jpg
I am using the same exact font, Impact. The problem is, when I add a black border shadow, the shadow is not visible enough and it's not wide enough. It's barely barely noticeable.
I am defining a FrameLayout, with the picture on the bottom and two text fields, one on the top and one on the bottom. The shadow is barely visible for both of them.
I have been using the parameters, shadowDy, shadowDx, etc. I know the shadowRadius is the parameter that actually defines the border size, but I have been experimenting both with values above 1 and below 1, and I can't seem to get any good results. There are minimal changes in size and shadow density, but nothing useful.
I have considered another option, which is a last resort, which is drawing the text twice, a bigger black font in the BG and align the character spacing so that the black text becomes the shadow of the white text on the front.
Thank you in advance !
You won't be able to accomplish that effect with the basic TextView shadows. I'd look at adding a stroke instead:
https://stackoverflow.com/a/2151964/321697
http://developer.android.com/reference/android/graphics/Paint.Style.html