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 StackOverflow!", 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? :)
The default font is 10px sans-serif.
Roboto is the default font on Android, and since 2013, other Google services such as Google Play, YouTube, Google Maps, and Google Images.
Canvas is a class in Android that performs 2D drawing of different objects onto the screen. The saying “a blank canvas” is very similar to what a Canvas object is on Android. It is basically, an empty space to draw onto. The Canvas class is not a new concept, this class is actually wrapping a SKCanvas under the hood.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With