我正在尝试在webview中向下滚动到页面底部,我正在使用谷歌在他们的教程中提供的webview示例。 我正在使用以下代码尝试滚动,但它不起作用。 mWebView.pageDown(true); 有关如何编程滚动的建议吗? 谢谢。
public class WebViewExample extends Activity {
private static final String LOG_TAG = "WebViewDemo";
private WebView mWebView;
private Handler mHandler = new Handler();
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setSavePassword(false);
webSettings.setSaveFormData(false);
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(false);
mWebView.setWebChromeClient(new MyWebChromeClient());
mWebView.addJavascriptInterface(new DemoJavaScriptInterface(), "demo");
mWebView.loadUrl("http://www.google.com/search?q=android+webview+scroll+doesnt+work&hl=en&safe=off&prmd=ivns&ei=0b0cTquNNI6WsgP6l7igBQ&start=10&sa=N#sclient=psy&hl=en&safe=off&source=hp&q=android%20webview%20scrollable&pbx=1&oq=&aq=&aqi=&aql=&gs_sm=&gs_upl=&bav=on.2,or.r_gc.r_pw.&fp=c306e119a7d85f91&biw=1280&bih=738&pf=p&pdl=300");
//this is where I try to scroll, doesn't work
mWebView.pageDown(true);
}
final class DemoJavaScriptInterface {
DemoJavaScriptInterface() {
}
/**
* This is not called on the UI thread. Post a runnable to invoke loadUrl on the UI thread.
*/
public void clickOnAndroid() {
mHandler.post(new Runnable() {
@Override
public void run() {
mWebView.loadUrl("javascript:wave()");
}
});
}
}
/**
* Provides a hook for calling "alert" from javascript. Useful for debugging your javascript.
*/
final class MyWebChromeClient extends WebChromeClient {
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
Log.d(LOG_TAG, message);
result.confirm();
return true;
}
}
}