Advertisement
hasancse1991

Untitled

Apr 20th, 2021
1,167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.61 KB | None | 0 0
  1. fun WebView.loadDataWithFont(htmlData: String) {
  2.     val fontAssetPath = "fonts/kalpurush.ttf"
  3.     val dataWithFont = "<html>" +
  4.         "<head>" +
  5.         "<style type=\"text/css\">" +
  6.         "@font-face {" +
  7.         "font-family: MyFont;" +
  8.         "src: url(\"" + "file:///android_asset/$fontAssetPath" + "\")" +
  9.         "}" +
  10.         "p,body {" +
  11.         "font-family: MyFont;" +
  12.         "}" +
  13.         "</style>" +
  14.         "</head>" +
  15.         "<body>" + htmlData +
  16.         "</body>" +
  17.         "</html>"
  18.  
  19.     this.loadDataWithBaseURL(null, dataWithFont, "text/html; charset=UTF-8", "UTF-8", null)
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement