Use custom external fonts in android application

Apply external font face style on TextView in android.

Android application with the use of external fonts make so much responsive our app. Using external custom fonts is very easy to apply on TextView tag and they can make any text look amazing like real web applications. Using my this tutorial you can upload fonts directly on your application and use them on your text. So here is the complete step by step tutorial for Use custom external fonts in android application.

android-project-download-code-button

How to Use custom external fonts in android application.

1. First Download required fonts from internet.

2. Create a new folder name ExternalFonts in assets folder and Paste all the downloaded fonts in it.

load fonts in app
Code for MainActivity.java file.

 package com.example.externalfontsapp;

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

TextView NewFontText;
Button ApplyExternalFonts;
String ExternalFontPath;
Typeface FontLoaderTypeface;
@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);

 NewFontText = (TextView)findViewById(R.id.textView1);
 ApplyExternalFonts = (Button)findViewById(R.id.button1);

 // Assests folder font folder path
 ExternalFontPath = "ExternalFonts/chopinscript.ttf";

 // Load Typeface font url String ExternalFontPath
 FontLoaderTypeface = Typeface.createFromAsset(getAssets(), ExternalFontPath);

 ApplyExternalFonts.setOnClickListener(new View.OnClickListener() {

 @Override
 public void onClick(View v) {

 NewFontText.setTypeface(FontLoaderTypeface);

 }
 });

 }
}

Code for activity_main.xml layout file.

 <RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.example.externalfontsapp.MainActivity" >

 <Button
 android:id="@+id/button1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_centerHorizontal="true"
 android:layout_centerVertical="true"
 android:text="CLICK HERE TO APPLY FONT STYLE" />

 <TextView
 android:id="@+id/textView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_above="@+id/button1"
 android:layout_centerHorizontal="true"
 android:layout_marginBottom="33dp"
 android:text="Android-Examples.com"
 android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

Screenshots:

without font

Use custom external fonts in android application

Click Here To Download Use custom external fonts in android application project.

Leave a Reply

Your email address will not be published. Required fields are marked *