The typeface class is used in the android SDK to define the font. You can set the font type by using the common font type name, such as setting the default:
Paint MP =
NewPaint ();
MP. settypeface (typeface. default_bold)
Common Font types include:
* Typeface. Default // Regular font type
* Typeface. default_bold // specifies the font type of the bold font.
* Typeface. monospace // same width font type
* Typeface. sans_serif // sans serif font type
* Typeface. serif // serif font type
In addition to font type settings, you can also set the font style for the font type, such as bold:
Paint MP =
NewPaint ();
Typeface font = typeface. Create (typeface. sans_serif, typeface. Bold );
P. settypeface (font );
Common font style names include:
* Typeface. Bold // bold
* Typeface. bold_italic // bold italic
* Typeface. italic // Italic
* Typeface. Normal // General
But sometimes the above settings do not work in the drawing process, so there are the following settings:
Paint MP =
NewPaint ();
MP. setfakeboldtext (
True); // True indicates bold, and false indicates non-bold.
MP. settextskewx (-0.5f); // float type parameter. A negative value indicates the Right oblique and an integer indicates the left oblique.
MP. setunderlinetext (
True); // True indicates the underline, and false indicates the non-underline.
MP. setstrikethrutext (
True); // True indicates strikethrough, and false indicates non-strikethrough.
Commonly used methods of painting include:
MP. settextsize (); // set the font size, int type, such as 12
MP. setstrokewidth (w); // set the line width and float type, such as 2.5f. You do not need to set the default value for text painting (the default value seems to be 0), but if it is set, when drawing the text again, it must be restored to 0.
Note: For bold Chinese settings, it seems that you can only use setfakeboldtext (true), although the effect does not look very real (font hollow effect ). The actual results are also related to the mobile phone hardware, such as the preceding drawing test program.
From: http://happyin1111.blog.163.com/blog/static/164184801201171911364435/