How to Use Font Awesome Icons in Android Application (2024)

In this article, I am going to show how to use the FontAwesome icons and symbols in native android application. To use font awesome icons in android application is very easy; just we place font code instead of text font. FontAwesome icons can be used using android TextView, Button View, etc. means fontawesome icons can be used like normal font and link it to fontawesome TTF file using java code.

Download and Import FontAwesome Font File

Let's take a look at an example.Download and import the FontAwesome TrueType file into your project. You can download the FontAwesome assets from GitHub.

When you download FontAwesome, you end up with an archive that includes a number of files and folders. Most of these are useful for web projects. We are only interested infontawesome-webfont.ttf, which is located in thefonts folder.

In your Android project, navigate toapp > src > main. Themain directory should include a folder namedassets.If there isn't one, then create it. In theassetsdirectory, create another folder, fonts, and addfontawesome-webfont.ttf to this folder.

Place FontAwesome Icons Code in Strings.xml File

To place font awesome icons code in android strings.xml file, give a name like normal strings and paste font awesome cheatsheet icons code like click here.

res/values/strings.xml

<resources> <string name="app_name">FontAwesome Icons</string> <string name="font_awesome_android_ic">&#xf17b;</string> <string name="font_awesome_area_chart_ic">&#xf1fe;</string> <string name="font_awesome_cubes_ic">&#xf1b3;</string> <string name="font_awesome_mobile_phone_ic">&#xf10b;</string></resources>

Insert FontAwesome Icons in Layouts File

In android layout file, add TextViews, Buttons, etc. to place font awesome icons wherever you want. Sample XML layouts file of android application looks like this.

res/layout/activity_main.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="mahesh.com.fontawesomeicons.MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="18dp" android:text="Font Awesome Icons" android:textSize="20sp" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:id="@+id/font_awesome_android_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center_horizontal" android:text="@string/font_awesome_android_ic" android:textColor="#80d204" android:textSize="50sp" /> <TextView android:id="@+id/font_awesome_area_chart_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center_horizontal" android:text="@string/font_awesome_area_chart_ic" android:textColor="#0491d2" android:textSize="50sp" /> <TextView android:id="@+id/font_awesome_cubes_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center_horizontal" android:text="@string/font_awesome_cubes_ic" android:textColor="#d27c04" android:textSize="50sp" /> </LinearLayout> <TextView android:id="@+id/font_awesome_mobile_phone_icon" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="30dp" android:gravity="center_horizontal" android:text="@string/font_awesome_mobile_phone_ic" android:textColor="#02a342" android:textSize="200sp" /> <TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:autoLink="web" android:gravity="center|bottom" android:text="ViralAndroid.com" android:textSize="24sp" android:textStyle="bold" /></LinearLayout>

Your layout is ready; it’s time to work in our java activity file to make working by font awesome fonts. Open your java activity file i.e. MainActivity.java file and place little bit code in onCreate method. MainActivity.java file will looks like below.

src/MainActivity.java

package mahesh.com.fontawesomeicons;import android.graphics.Typeface;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.widget.TextView;public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Typeface fontAwesomeFont = Typeface.createFromAsset(getAssets(), "fontawesome-webfont.ttf"); TextView fontAwesomeAndroidIcon = (TextView) findViewById(R.id.font_awesome_android_icon); TextView fontAwesomeAreaChartIcon = (TextView) findViewById(R.id.font_awesome_area_chart_icon); TextView fontAwesomeCubesIcon = (TextView) findViewById(R.id.font_awesome_cubes_icon); TextView fontAwesomeMobilePhoneIcon = (TextView) findViewById(R.id.font_awesome_mobile_phone_icon); fontAwesomeAndroidIcon.setTypeface(fontAwesomeFont); fontAwesomeAreaChartIcon.setTypeface(fontAwesomeFont); fontAwesomeCubesIcon.setTypeface(fontAwesomeFont); fontAwesomeMobilePhoneIcon.setTypeface(fontAwesomeFont); }

You have done all things. Now, run your source code.

Conclusion

In this quick tip, I showed you how to use the FontAwesomeicon set in an Android project. FontAwesome iswidely known, very rich, and free. The result is sharp and crisp icons, even on high resolution displays. As an added bonus, changing an icon's size or color is as simple as changing an XML attribute.

Thank you..!!

How to Use Font Awesome Icons in Android Application (2024)
Top Articles
Can you Save Money Without a Bank Account?
How to Buy First Property in Upland | How to Earn UPX in Upland & Trade property Upland
Ixl Elmoreco.com
Flixtor The Meg
Gore Videos Uncensored
Hertz Car Rental Partnership | Uber
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Mawal Gameroom Download
Volstate Portal
Monticello Culver's Flavor Of The Day
Declan Mining Co Coupon
Tcu Jaggaer
Sports Clips Plant City
Chic Lash Boutique Highland Village
Apne Tv Co Com
What Happened To Anna Citron Lansky
Bx11
Obsidian Guard's Cutlass
[Cheryll Glotfelty, Harold Fromm] The Ecocriticism(z-lib.org)
Allentown Craigslist Heavy Equipment
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
Laveen Modern Dentistry And Orthodontics Laveen Village Az
Ups Drop Off Newton Ks
Aol News Weather Entertainment Local Lifestyle
Coomeet Premium Mod Apk For Pc
What Are The Symptoms Of A Bad Solenoid Pack E4od?
Sadie Sink Reveals She Struggles With Imposter Syndrome
Ontdek Pearson support voor digitaal testen en scoren
Elite Dangerous How To Scan Nav Beacon
Rek Funerals
Devotion Showtimes Near The Grand 16 - Pier Park
How to Use Craigslist (with Pictures) - wikiHow
Nacogdoches, Texas: Step Back in Time in Texas' Oldest Town
Gr86 Forums
Teenbeautyfitness
Hair Love Salon Bradley Beach
The Mad Merchant Wow
To Give A Guarantee Promise Figgerits
Craigslist List Albuquerque: Your Ultimate Guide to Buying, Selling, and Finding Everything - First Republic Craigslist
Ramsey County Recordease
Jack In The Box Menu 2022
Homeloanserv Account Login
How I Passed the AZ-900 Microsoft Azure Fundamentals Exam
8776725837
Wpne Tv Schedule
Graduation Requirements
Underground Weather Tropical
Tommy Gold Lpsg
The Goshen News Obituary
What Is The Gcf Of 44J5K4 And 121J2K6
Jesus Calling Oct 6
Latest Posts
Article information

Author: Geoffrey Lueilwitz

Last Updated:

Views: 6349

Rating: 5 / 5 (60 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Geoffrey Lueilwitz

Birthday: 1997-03-23

Address: 74183 Thomas Course, Port Micheal, OK 55446-1529

Phone: +13408645881558

Job: Global Representative

Hobby: Sailing, Vehicle restoration, Rowing, Ghost hunting, Scrapbooking, Rugby, Board sports

Introduction: My name is Geoffrey Lueilwitz, I am a zealous, encouraging, sparkling, enchanting, graceful, faithful, nice person who loves writing and wants to share my knowledge and understanding with you.