How to draw with a default Android font on a Canvas?
I'm trying to draw a text on Canvas like this (kinda pseudocode below):
Paint p = new Paint(ANTI_ALIAS_FLAG);
p.setTextSize(18);
...
mCanvas.drawText("Hello Stac开发者_高级运维kOverflow!", 50, 50, p);
My problem is that the result looks really "weird". It uses some bold-like font, which is badly aliased, looks not pretty and "squarish".
I tried to play with p.setTextSize(), by setting various sizes, also I tried to set different default Typefaces by using p.setTypeface(Typeface) and setting DEFAULT, NORMAL, SERIF, SANS_SERIF etc, but it still looks ugly.
On the contrary the font used throughout the rest of the system looks really nice, and I'd like to use it.
How? :)
This will alias the font properly:
p.setAntiAlias(true);
If you want to change the font itself, then use
p.setTypeface(yourTypeface);
with a custom Typeface object.
(take a look at http://developer.android.com/reference/android/graphics/Typeface.html)
You can use
Typeface.defaultFromStyle(int style);
together with one of the text styles here: http://developer.android.com/reference/android/R.style.html#TextAppearance.
It should give you the default system font style, if that is what you're after.
精彩评论