css - Asset font is not loaded in android webView -


I am developing an Android activity that is loading an HTML file in a webline
although it ACCT is not loading fonts in some phones eg. 4.4 or 4.1 HTC Desire or Sony Xperia Z with Android
I want to know whether I'm missing something or it just depends on the phone which I'm testing my app.

  Private zero loadtovers (strings) {try {pageWebView} LoadDataWithBaseURL ("file: /// android_asset /", s, "text / html", "utf-8", tap); ConfigureWebView (pageWebView); } Hold (exception e) {e.printStackTrace (); }}  

Here's the html header:

   & Lt; Style type = "text / css" & gt; @ Font-faces {font-family: 'Persian'; Src: url ('file: ///android_asset/fonts/b_yekan.ttf'); } @ Font-face {font-family: 'Persian 2'; Src: url ('file: ///android_asset/fonts/b_homa.ttf'); } @ Font-faces {font-family: 'PersianTitle'; Src: url ('file: ///android_asset/fonts/b_titr.ttf')}} body {font-family: 'Persian';} h1 {font-family: 'PersianTitle';} h2 {font-family: Persian 2 ';} & lt; / Style & gt;  

fonts are located in property / fonts /
 Enter image description here:> </ p> </ div> <p> <div class =

  • first , font The path should be relative to your html / css file.

Then, instead of:

  @ font-face {font-family: 'Persian'; Src: url ('file: ///android_asset/fonts/b_yekan.ttf'); }  

Use something like this:

  @ font-face {font-family: 'Persian'; Src: url ('fonts / b_yekan.ttf'); }  
  • Second , you must ensure that the goal you are testing is actually supporting Arabic script.

    With this, I am providing a working example below.


    Assets / About / u.html:

       & Lt; Style type = "text / css" & gt; @ Font-face {font-family: 'b homa'; Src: url ('fonts / BHOMA.TTF');} @ font-face {font-family: 'B lotus'; Source: 'B Lotus Bold'; Src: url ('fonts / BLOTUSBD.TTF');} & lt; / Style & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; P style = "font-family: 'b homa'; font-size: 20px;" & Gt; B Homa: Michael & lt; / P & gt; & Lt; P style = "font-family: 'b lotus', font-size: 20px;" & Gt; B. Lotus: Michael & lt; / P & gt; & Lt; P style = "font-family: 'b lotus bold'; font-size: 20px;" & Gt; B. Lotus Bold: Michael & lt; / P & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

    BHOMA.TTF , BLOTUS.TTF and BLOTUSBD.TTF are downloaded and stored. > Property / fonts / folder.

    loadToWebView () , this is part of a piece , hence the getActivity () .getAssets () :

      Private zero load tabview () {AssetManager assetManager = getActivity (). GetAssets (); {Try InputStream input = assetManager.open ("about_us.html"); Byte [] buffer = new byte [input Unavailable ()]; Input.read (buffer); Input.close (); MWebView.loadDataWithBaseURL ("File: /// and Android_set /", new string (buffer), "text / html", "UTF-8", blank); } Grip (IOException E) {// TODO Auto-Generated Catch Block e.printStackTrace (); }}  

    more results :

    screenshot

    Hope this will be helpful.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -