user2857021
user2857021

Reputation:

custom font for webview android

I use a webview in my app and i want display text in farsi language with custom font .I place my font in asset folder and write a method for place text in webview but in api8 that dont support farsi language .it dispaly unknown characters instead of my text and in apies that support farsi language it dont display my text by custom font and it display my text by default font .what is wrong in my method.thanks my method

  public void setText(String text)
{
    String style2="<style type=\"text/css\">@font-face {font-family: 'myface';src: url('file:///android_asset/BYekan.ttf'); } body {font-family: 'myface';}</style>";
    this.loadDataWithBaseURL("file:///android_asset/BYekan.ttf","<html  dir=\"rtl\"><head><meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\"/>"+style2+"</head><body>"+text+"</body></html>","text/html","UTF-8",null);
    setClickable(false);
    setLongClickable(false);
    setFocusable(false);
    setFocusableInTouchMode(false);
}

Upvotes: 8

Views: 4210

Answers (1)

Luis
Luis

Reputation: 3571

Your style should look something like this:

@font-face{ 
font-family:myface;
font-weight:normal;
font-style:normal;
src:url('file:///android_asset/BYekan.ttf') format('truetype');
}

Upvotes: 1

Related Questions