You need to get the path to style.css and for the file to see local fonts for the image files. I want to insert a path here

String text = "<html><head>" + "<link href=\"file:///android_asset/style.css\">" // + "<style type=\"text/css\">"+textr+"</style>" // + "<style type=\"text/css\">body{color: #c1c1c1; background-color: #303030;}</style>" + "</head>" + "<body>" + elWeb + "</body></html>"; 

I wrote like this file: ///android_asset/style.css, does not work (but takes the style from the site) Now I use

 InputStream is = getActivity().getAssets().open("style.css"); int size = is.available(); byte[] buffer = new byte[size]; is.read(buffer); is.close(); String textr = new String(buffer); 

But it does not suit me

  • Do you ship it in WebView? I suspect that through loadData. Try through loadDataWithBaseURL, specifying "file: /// android_asset" as baseURL. rtfm - Yura Ivanov
  • @YuraIvanov, thank you very much. It works, but you don’t know I have links in html as the base file: /// android_asset they won’t open if you can redirect it somehow. As I use jsoup, the links may change - Artem
  • @YuraIvanov, Answer the question, or close the topic. This answer solves my problem - Artem

1 answer 1

In order to perceive relative links to local files, in particular, to files in assets, you must load the page using loadDataWithBaseURL , specifying the base url, in particular for assets:

 webView.loadDataWithBaseURL("file:///android_asset", html,...) 

Threat If the links lead to other servers, then they will have to change and absolute to the server where the resource is located. ZZY It is possible that there are other solutions to the original problem, for example, injection of local files using javascript methods ...

  • thanks again, I also decided this question - Artem