Set custom font for webview in android

How to set custom font in webview in android

This is an Example of Set typeface for webview in android using HTML. In this view set the typeface in HTML String and load with Webview.  Put the font in the Assets folder.

Custom font location

Every android device having default font. By using typeface is required to give your application look and feel good.CLICK HERE to know more about the typeface.

Related Post

How to get current latitude and longitude in android example

Drag And Drop Listview Android

Pagination with Recyclerview in android

Step: 1

create a new Android application project and copy these code into the XML file.


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" >
        android:layout_height="match_parent" />

Step: 2

create a in the src folder and copy these code.

import android.os.Bundle;
import android.view.Window;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
    WebView mWebView;
    String htmlstr1="<p style='text-align:right'><H2>Android Toppers</H2></p> <p style='text-align:left'>It is safer to use a JSON parser to convert a JSON text to a JavaScript object.</p>";
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        mWebView = (WebView) findViewById(;
        mWebView.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub
                return true;
        String head1 = "<head><style>@font-face {font-family: 'arial';src: url('file:///android_asset/fonts/bichkam.ttf');}body {font-family: 'verdana';}</style></head>";
        String text="<html>"+head1
                + "<body style="font-family: arial">" + htmlstr1
                + "</body></html>";
        mWebView.loadDataWithBaseURL("", text, "text/html", "utf-8", "");


Custom font in webview demo


I hope this post is helpful for you. Please share you feedback in the comments section.

Download example code

4 thoughts on - How to set custom font in webview in android

Leave a Reply

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