Skip to content

Instantly share code, notes, and snippets.

@andrea-ale-sbarra
Last active December 8, 2021 09:29
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save andrea-ale-sbarra/7984974 to your computer and use it in GitHub Desktop.
Save andrea-ale-sbarra/7984974 to your computer and use it in GitHub Desktop.
How to add custom font in Android WebView.
//View container..
View rootView = inflater.inflate(R.layout.fragment1, container, false);
//Global WebView
mWebView = (WebView) rootView.findViewById(R.id.enter_text);
//Font must be placed in assets/fonts folder
String text = "<html><style type='text/css'>@font-face { font-family: spqr; src: url('fonts/spqr.ttf'); } body p {font-family: spqr;}</style>"
+ "<body >" + "<p align=\"justify\" style=\"font-size: 22px; font-family: spqr;\">" + getString(R.string.enter_text) + "</p> "+ "</body></html>";
mWebView.loadDataWithBaseURL("file:///android_asset/",text,"text/html","utf-8",null);
return rootView;
@ahm507
Copy link

ahm507 commented Aug 11, 2018

cool, thank you

@gitbharatarmy
Copy link

thank you

@1mike12
Copy link

1mike12 commented Apr 6, 2021

very cool, very legal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment