Set the paint font attribute in Android

Source: Internet
Author: User

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 = new paint();
mp.setTypeface(Typeface.DEFAULT_BOLD)

CommonFont type nameAlso:

  • Typeface. Default // Regular font type
  • Typeface. default_bold // font type
  • 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 = new Paint();
Typeface font = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD);
p.setTypeface( font );

CommonFont Style nameAlso:

  • Typeface. Bold // bold
  • Typeface. bold_italic // bold italic
  • Typeface. italic // Italic
  • Typeface. Normal // regular

But sometimes the above settings do not work in the drawing process, so there are the following settings:

Paint mp = new Paint();
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. For example, the above plot test program did not display a blank line of Chinese characters (English and numbers are normal) in HTC ), however, one line in italic is displayed in reverse order, but it does not have italic effect. Meizu M9 is very powerful. It may be because the Android system customized by M9 has a wide array of character libraries!

 

Source: http://www.ucrobotics.com/index.php/en/forum/18-Android%E6%8A%80%E6%9C%AF%E6%8E%A2%E8% AE %A8/82-Android%E4%B8%ADPaint%E5%AD%97%E4%BD%93%E5%B1%9E%E6%80%A7%E7%9A%84%E8% AE %BE%E7%BD% AE

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.