Monday, August 25, 2014

How to Set typeface for HTML String in Android

How to Set typeface for HTML String in Android
This post about how set the typeface for Html string and load to webview.
#put your font file into asset folder.

Screen Shot

Activity Code
package com.example.supportmultiplelanguge;



import android.annotation.SuppressLint;


import android.os.Bundle;

import android.webkit.WebView;

import android.webkit.WebViewClient;

import android.widget.Button;


public class MainActivity extends Activity {

       Button arabic_btn;

       String htmlStr = "<p style='text-align:right'>العذر يا بوي لو ماشلّني ساقي</p><p style='text-align:left'>الحزن ما طاقني والقلب ما طاقه</p><p style='text-align:right'> ياعيني ابكي وساعدها يا خفّاقي</p>";

       WebView webView;

       protected void onCreate(Bundle savedInstanceState) {



              webView = (WebView) findViewById(;

              webView.setWebViewClient(new WebViewClient() {

                     public boolean shouldOverrideUrlLoading(WebView view, String url) {


                           return true;



              String head = "<head><style>@font-face {font-family: 'arial';src: url('file:///android_asset/fonts/HelveticaNeueLTArabic-Bold.ttf');}body {font-family: 'verdana';}</style></head>";

              String htmlData = "<html>" + head
                           + "<body style=\"font-family: arial\">" + htmlStr
                           + "</body></html>";

              webView.loadDataWithBaseURL("", htmlData,

              "text/html", "utf-8", "");



No comments:

Post a Comment

Check out this may be help you

Related Posts Plugin for WordPress, Blogger...