How to Programmatically Scroll Android Webview

How to Programmatically Scroll Android WebView

I've found a better answer to this issue. It turns out that WebView does have scrollTo(), getScrollX() and getScrollY() methods as you'd expect. They're a bit hidden in the documentation because they're inherited from View (via AbsoluteLayout -> ViewGroup -> View). This is obviously a better way to manipulate the WebView's scroll position than the somewhat cumbersome JavaScript interface.

Android Webview scroll to bottom programmatically (Kotlin)

Just replace

wvMain.scrollTo(0, height)

By

wvMain.scrollTo(0, height * getResources().getDisplayMetrics().density.toInt())

By this you will get actual height of WebView in pixels as per device screen density

I guess you will get your desired result.

Scroll to HTML content in WebView

Maybe not directly with WebView but with javascript. If you have a js function to scroll to an element such as this :

function scrollTo(element){
document.getElementById(element).scrollIntoView();
}

You can call it from WebView with

mWebView.loadUrl("javascript:scrollTo('element')");

Just make sure javascript is enabled in WebView

mWebView.getSettings().setJavaScriptEnabled(true);

Programmatic scroll of Webview isn't reflected when drawing from Canvas

FINALLY found the answer from here:

You have to call WebView.enableSlowWholeDocumentDraw() before inflating the view in your fragment.



Related Topics



Leave a reply



Submit