开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜