I have an Android page that features a WebView
. I initially generate some HTML and load it into the webview using some code that looks like:
String ASSET_DIR = "file:///android_asset/subdir/";
webview.loadDataWithBaseURL(ASSET_DIR, html, "text/html", "UTF-8", null);
In the onPageFinished
callback to my WebViewClient
, I want to scroll the view to an anchor in the generated html. In that callback, I call
webview.loadUrl(ASSET_DIR + "#" + myAnchor);
On older versions of WebView
(44), this works fine, but on newer versions (70), I get the error:
The webpage at file:///android_asset/subdir/#myAnchor could not be loaded because: net::ERR_FILE_NOT_FOUND
I've tried adding permissions to webview.getSettings()
, but without success. How do I fix this?
Note: I'd like to avoid using Javascript to solve this issue. I tried a solution with findElementById.scrollIntoView
, but it scrolls off the page on newer WebView
versions.