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
Clear Application Cache on Exit in Android
How to Detect a Dual-Core CPU on an Android Device from Code
Delete File from Internal Storage
Android Emulator - Trouble Creating User Accounts
Include Stetho Only in the Debug Build Variant
Android:Dither="True" Does Not Dither, What's Wrong
How to Access an Image from the Phone's Photo Gallery
Set Unchangeable Some Part of Edittext Android
How to Get Information About Android Battery Usage by Application
Set Build Path in Eclipse for Ndk Program
Getting Header from Response (Retrofit/Okhttp Client)
Android: Unicode/Charset Problems When Sending an Sms (Sendtextmessage)
How to Check If Running on UI Thread in Android
Playing Local Sound in Phonegap