Monday 9 March 2015

Android applying custom fonts

Hello Friends,
      Today, I am sharing my small blog which helps you in applying custom fonts
on android text view from xml or styles file. Its very easy and reduces the number
of java line from your code and also make the performance of your app more better.

1.Placed all your custom fonts file inside assets folder i.e: assets/fonts/digitalism.ttf)
2.Add the path of above custom font file your string.xml file
<string name="FONT_d3_digitalism">fonts/d3-digitalism.ttf</string>
<string name="FONT_digitalism">fonts/digitalism.ttf</string>
<string name="FONT_Mohave_Bold">fonts/Mohave-Bold.ttf</string>
<string name="FONT_Roboto_Black">fonts/Roboto-Black.ttf</string>
<string name="FONT_Roboto_Bold">fonts/Roboto-Bold.ttf</string>
<string name="FONT_Roboto_Medium">fonts/Roboto-Medium.ttf</string>
<string name="FONT_RobotoCondensed_Bold">fonts/RobotoCondensed-Bold.ttf</string>

3. Declartion of style inside values/styles.xml file for eg:
        <style name="CustomDigital">
          <item name="font">@string/FONT_digitalism</item>

4. Inside attrs.xml add this:
<?xml version="1.0" encoding="utf-8"?>
      <declare-styleable name="Fontify">
<attr name="font" format="string" />

   <!-- Allows attribute use in an AppTheme definition -->
   <declare-styleable name="FontifyTheme">
<attr name="fontifyStyle" format="reference"/>
5. finally, In our layout file we have to use this :
         android:text="TextClock" />

For more check below link:

Download Demo Code : CustomTextFont

Hope this will help some one.
Enjoy Coding :)


Copyright @ 2013 Android Developers Blog.