This Is How You Can Use Custom Fonts In Android Studio

This Is How You Can Use Custom Fonts In Android Studio

Beautify Your Project With Custom Font(s)😉

·

3 min read

Case Scenario

  • When You Are Working On A Project You May Need To Use Custom Fonts As Per Your Necessity. You May Already Know That Android Studio Provides Us Few Pre-Added Fonts In Our Project Which May Not Suite every time😕

Prerequisite

  • Before Going To Further Make Sure That You Have Downloaded Your Necessary Font Files And Extracted Them[If It Is A Compressed File]

Getting Started:

  • First Things First, Copy Those Font Files Which You Have Downloaded Earlier As Shown As Below:

Capture3.PNG

  • Now Enter To Magical World Of Android Studio, Extended Projects Panel If It Is Collapsed As Shown Below:

Capture1.PNG

  • Now Extended app Directory And You Have To See Directory/Folder Named As res :

Capture2.PNG

  • Now Right Click On res Folder/Directory And You Have To See Something Like This:

Capture4.png

  • Now Click On New And Then Click On Directory :

Capture5.png

  • Now Name Directory As font And Click Enter Which Will Create A Directory In Your res Folder As Shown Below:

Capture6.png

  • Now Click CTRL+V In Your Keyboard Or Paste Those Font Files Which We Have Copied Earlier; In font Directory, And You Have To See This Popup/Dialog Box Shortly After Pasting Those Font Files 👇🏻

Capture8.png

  • Click Ok To Paste Those Font Files

  • Make Sure That Font Files Name Should Be In LOWERCASES ONLY If It's Not, Just Rename Them After Clicking Ok.

  • Boom👊🏻, We Have Successfully Added Those Font Files In Our Project.

  • If You Want To Preview Those Font Files Just Double Tap On Font File Which You Want To Preview As Shown Below:

Capture10.png

  • Now Open Layout File/XML File And Add Text View:

Capture12.png

  • You Can Actually Notice That Text Font Is Default Font Which we Will Change In Further.

Note1:- In My Case, I am Using Constraint Layout Depending On Your Layout You Can Change Those Attributes

Note2:- You Can Change Font Of Any Text Which May Be Present In Any Element.

  • For Example:- In Button Element We Need To Define Text Where We Define Button Usage And Here With The Help Of Same Attributes Which You Are Using For Text View Can Be Used In Button Element To Change Button’s Text Font

  • Now In Your Text View/Other Elements Where Text Can Be Added; Add Font As Shown In Below Code:

Capture13.png

Note:-There Are Two Attributes To Add Font(s), You Can Choose Anyone

First Attribute:-

android:fontFamily="fontfilename"

Second Attribute:-`

app:fontFamily="fontfilename"

And As I Said You Can Only Choose One Attribute In My Case I Have Implemented The First Attribute Which Looks Like Below:

Capture15.png

Now Our Layout File Should Look Like This And Also You Can See That Font Has Been Changed in Design View:

Capture16.png

  • And There We Go! We Have Successfully Added Custom Font(s) In Our Project🤩

Well, That's All For Now🙌

Bye🤗