Android flat screen design-use Font-awesome in Android

Source: Internet
Author: User

Font-awesome is an icon collection font designed for bootstrap, which contains more than 300 commonly used icons. Using Font-awesome also has the following advantages:

1, reduce the drawing of the icon work

2, suitable for flat design of the interface

3, the size of the icon and the color can be set in the code itself, the bukkake is not fixed, can be large variability

4, reduce the size of the APK

How to use Font-awesome:

To http://fortawesome.github.io/Font-Awesome/download Font-awesome fonts, Currently the latest version is 4.3.0 then unzip the package and place the Fontawesome-webfont.ttf file under the Fonts folder under the assets directory of the project. To http://fortawesome.github.io/Font-Awesome/cheatsheet/view the corresponding icon, you can download the page to save it. You can also find in the Font-awesome.css file in the CSS directory of the downloaded Font-awesome font, I have tried, I really do not see which icon, so still in the http://fortawesome.github.io/ Font-awesome/cheatsheet better.

Then define your icon in the strings file under the values folder, such as my heart icon so defined in Strings.xml: <string name= "heard" >& #xf004; </string >. The TextView is then defined in the layout file, such as:

<textview
Android:id= "@+id/test_view"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "@string/heard"//Note this must not be forgotten
Android:textsize= "50SP"
Android:textcolor= "#F59012"
Android:textappearance= "? Android:attr/textappearancelarge"/>

Then in Java code, you define TextView in your activity.

 Public classLoginactivityextendsActivityImplementsonclicklistener{PrivateTextView T1;@Overrideprotected voidonCreate (Bundle savedinstancestate) {//TODO auto-generated Method Stub        Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.login); Typeface Font= Typeface.createfromasset (Getassets (), "Fontawesome-webfont.ttf");//Remember to add this sentence T1=(TextView) Findviewbyid (R.id.test_view);t1.settypeface (font); 
Typeface font = Typeface.createfromasset (Getassets (), "Fontawesome-webfont.ttf");
Settypeface (font); this cannot be forgotten. Then run your project and you'll see the icon you want in the TextView.

As simple as this, the individual feels much better than what they are designed to do, and the flat style fits the style of the interface design.

If you need help please leave a message, Welcome to discuss!

Android flat screen design-use Font-awesome in Android

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.