Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android set custom font to a paint

I want to draw a text to a paint. How to draw it with a custom font (ex Helvetica ) and bold also? I would preffer to use a system font and not create it from assets. Thanks.

like image 594
Buda Gavril Avatar asked May 18 '11 10:05

Buda Gavril


People also ask

How do I use OTF files on Android?

To change font styles in GO Launcher, copy the TTF or OTF font files on your phone. Long press on the home screen and select GO Settings. Choose Font–>Select Font. Pick the font you want or tap Scan to add files stored on your device.

What format does Android use for fonts?

Fonts are compiled in R file and are automatically available in the system as a resource. You can then access these fonts with the help of the font resource type.


1 Answers

If by "custom font" you mean a font that you are supplying as an asset, the following code should work:

Typeface plain = Typeface.createFromAsset(assetManager, pathToFont);  Typeface bold = Typeface.create(plain, Typeface.DEFAULT_BOLD) Paint paint = new Paint(); paint.setTypeface(bold); canvas.drawText("Sample text in bold",0,0,paint); 
like image 96
Tony the Pony Avatar answered Sep 23 '22 09:09

Tony the Pony