@JavascriptInterface
public void resize(final float height) {
WebViewActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
//Toast.makeText(getActivity(), height + "", Toast.LENGTH_LONG).show();
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)mWebView1.getLayoutParams();
layoutParams.width = getResources().getDisplayMetrics().widthPixels;
layoutParams.height = (int) (height * getResources().getDisplayMetrics().density);
mWebView.setLayoutParams(layoutParams);
}
});
}
or
@JavascriptInterface
public void resize(final float height) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
//Toast.makeText(getActivity(), height + "", Toast.LENGTH_LONG).show();
mWebView.setLayoutParams(new LinearLayout.LayoutParams(getResources().getDisplayMetrics().widthPixels, (int) (height * getResources().getDisplayMetrics().density)));
}
});
}
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
mWebView.loadUrl("javascript:App.resize(document.body.getBoundingClientRect().height)");
super.onPageFinished(view, url);
}
});
mWebView.addJavascriptInterface(this, "App");