Saturday, August 29, 2015

Using FontAwsome icons in Android

FontAwsome is providing a lot of standard assets which can be used along with TextView. The real power of these assets is to apply text properties ( color, text size etc) which automatically changes the asset/ image appearance. Follow the below steps.


  • Download fontawesome-webfont.ttf into your assets folder. Get it from the project https://github.com/bperin/FontAwesomeAndroid. Find the .ttf file inside the project and place it in your assets folder.
  • Get familiar with the cheatsheet which has all the icons.Please find it here.
    • I'm considering fa-angle-right from cheat sheet which is frequently used as a right arrow in lists.
    • Now copy the value of  fa-angle-right to string. String name fa_andle_right and value is 
  • It's time for the TextView to make use of the right arrrow. Create a textview as below and assign text as fa_right_arrow.
    • "wrap_content"
              android:layout_height="wrap_content"
              android:id="@+id/tv_rightarrow"
              android:text="@string/fa_right_arrow"
              android:textSize= "16sp"
              android:textColor="@android:color/holo_red_dark"
              android:layout_margin="10dp"/>
  • Just one last step. Change the typeface of the TextView
    • Typeface font = Typeface.createFromAsset(getAssets(), "fontawesome-webfont.ttf");
              TextView rightArrowTV = (TextView)findViewById( R.id.tv_rightarrow );
              rightArrowTV.setTypeface(font);
    Run the code and see the magic. 
    Now it's less dependency on designers.

    Cheers.

    3 comments:

    1. Thanks for sharing Harsha . . It's really useful :)

      ReplyDelete
    2. This comment has been removed by the author.

      ReplyDelete
    3. The Borgata Hotel Casino & Spa
      Borgata Hotel Casino & 성남 출장마사지 Spa · Casino and Spa 구리 출장마사지 Hotel in Atlantic City, 파주 출장마사지 NJ · The Spa at Borgata · The Spa at Borgata Hotel Casino & Spa · The 서귀포 출장샵 Spa at Borgata · The Spa at 전라남도 출장마사지 Borgata

      ReplyDelete