1、设置webview属性:
webView.setWebChromeClient(new MyWebChromeClient());
webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setPluginState(WebSettings.PluginState.ON);
webSettings.setUseWideViewPort(true);
webSettings.setAllowFileAccess(true);
webSettings.setSupportZoom(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
webSettings.setUseWideViewPort(true);
webView.addJavascriptInterface(new JavaScriptObject(this), "android");
2、设置AndroidManifest.xml:
//开启硬件加速
<activity android:name=".webview.WebViewAdActivity" android:hardwareAccelerated="true"/>
3、关闭界面任在播放的问题:
@Override
public void onPause() {
super.onPause();
webView.onPause();
webView.pauseTimers();
} @Override
public void onResume() {
super.onResume();
webView.resumeTimers();
webView.onResume();
} @Override
protected void onDestroy() {
webView.destroy();
webView = null;
super.onDestroy();
}