How to Use iconfont in Android, androidiconfont

Source: Internet
Author: User

How to Use iconfont in Android, androidiconfont
1. iconfont

Iconfont is both an icon and a font. Specifically, it should be an icon displayed in the font form. Unlike the icon in the traditional image format, this icon is displayed in a font, so it is very convenient to change the size, color, and background color.

2. Use method 2.1 to download resources

Resource Source: http://www.androidicons.com/

Find the download link as instructed. Download and decompress the package, find the iconfont/font, and copy the four files to the assets Directory of the Android project. Find glyphs/glyphs.html. Because it will be used later, copy it to the assets Directory.

2.2 add icon

You can add TextView, Button, and other controls here. When setText () is used, the code corresponding to the icon is passed as a parameter. To the code corresponding to the map, open glyphs.html, find the icon you want to add, and copy the last line below, for example, "& #59428 ;".

2.3 set the font (Typeface)
Typeface iconTypeface = Typeface. createFromAsset (getAssets (), "androidicons. ttf"); textView = (TextView) findViewById (R. id. iconView); textView. setTypeface (iconTypeface );

Typeface. createFromAssets () the first parameter is the AssetManager object, which is obtained through getAssets (). The second parameter is the path. As shown in the Code, the path is assets/androidicons. ttf ".

Note: When I use eclipse, I cannot see the added icon in the preview. I can only see it in the simulator, and I don't know if it is a problem with eclipse.

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.