Android textview advanced display skills example summary

This article summarizes the advanced display skills of Android textview. Share with you for your reference, as follows:

1. Custom font

You can use the settypeface (typeface) method to set the font of the text in the text box, while the Android typeface uses the TTF font file to set the font

Therefore, we can put the TTF font file in the program and use typeface to set the font in the program: first, create a new fonts directory under the assets directory and put the TTF font file here. The second step is to call in the program:

The effect is shown in the following figure:

2. Display words of multiple colors

Android supports strings in HTML format by calling HTML The fromhtml (STR) method can convert the string STR in HTML format.

Examples are as follows:

The effect after operation is as follows:

3. Bold font

Using Android: TextStyle = "bold" in the XML layout file, you can set English to bold, but you can't set Chinese to bold. To set Chinese to bold, use textpaint's imitation "bold" to set setfakeboldtext to true. The example code is as follows:

The effects are as follows:

4. Add shadows

Use a series of Android: shadowxxx attributes in the XML layout file to add and set shadows. Specifically: shadowcolor sets the shadow color; Shadowdx sets the shadow horizontal offset; Shadowdy sets the shadow vertical offset; Shadowradius sets the shadow radius.

Example code:

The display effect is as follows:

5. Insert picture

There are two methods to insert images. The first method is to use the above HTML format string, but the conversion is a little troublesome. You need to use the imagegetter class to convert the SRC property of the image. The example code is as follows:

The second method is to use a series of Android: drawablexxx attributes in the XML layout file to insert images. Specifically: drawablebottom is to draw a specified image at the bottom of the text in the text box; Drawableleft is to draw the specified image on the left side of the text in the text box; Drawableright is to draw the specified image on the right side of the text in the text box; Drawabletop is to draw a specified image at the top of the text in the text box; Drawablepadding sets the spacing between the text and the image in the text box. Example code:

The display effect after inserting a picture is as follows:

More readers interested in Android related content can view the topics on this site: summary of Android view skills, summary of Android layout skills, summary of Android graphics and image processing skills, introduction and advanced tutorial of Android development, summary of Android debugging skills and solutions to common problems, and summary of Android multimedia operation skills (audio, video, recording, etc.), usage summary of Android basic components and Usage Summary of Android controls

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>