Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It can be done in Android. I took three days to solve this issue. But now it seems very easy. Follow these steps to set custom font for Webview</p> <p>1.Add your font to assets folder<br> 2.Copy the font to application's files directory</p> <pre><code>private boolean copyFile(Context context,String fileName) { boolean status = false; try { FileOutputStream out = context.openFileOutput(fileName, Context.MODE_PRIVATE); InputStream in = context.getAssets().open(fileName); // Transfer bytes from the input file to the output file byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) &gt; 0) { out.write(buf, 0, len); } // Close the streams out.close(); in.close(); status = true; } catch (Exception e) { System.out.println("Exception in copyFile:: "+e.getMessage()); status = false; } System.out.println("copyFile Status:: "+status); return status; } </code></pre> <p>3.You have to call above function only once (you have to find some logic for this).</p> <pre><code>copyFile(getContext(), "myfont.ttf"); </code></pre> <p>4.Use the below code to set value for your webview. Here I am using CSS to set font.</p> <pre><code>private String getHtmlData(Context context, String data){ String head = "&lt;head&gt;&lt;style&gt;@font-face {font-family: 'verdana';src: url('file://"+ context.getFilesDir().getAbsolutePath()+ "/verdana.ttf');}body {font-family: 'verdana';}&lt;/style&gt;&lt;/head&gt;"; String htmlData= "&lt;html&gt;"+head+"&lt;body&gt;"+data+"&lt;/body&gt;&lt;/html&gt;" ; return htmlData; } </code></pre> <p>5.You can call the above function as below</p> <pre><code>webview.loadDataWithBaseURL(null, getHtmlData(activity,htmlData) , "text/html", "utf-8", "about:blank"); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload