微信X5之WebView使用 发表于 2019-05-16 #微信X5之WebView使用 X5之WebView属性配置12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 private WebViewClient client = new WebViewClient() { /** * 防止加载网页时调起系统浏览器 */ public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; }};public X5WebView(Context arg0) { super(arg0); setBackgroundColor(85621);}@SuppressLint("SetJavaScriptEnabled")public X5WebView(Context arg0, AttributeSet arg1) { super(arg0, arg1); this.setWebViewClient(client); // this.setWebChromeClient(chromeClient); // WebStorage webStorage = WebStorage.getInstance(); initWebViewSettings(); this.getView().setClickable(true);} private void initWebViewSettings() { WebSettings webSetting = this.getSettings(); webSetting.setJavaScriptEnabled(true); webSetting.setJavaScriptCanOpenWindowsAutomatically(true); webSetting.setAllowFileAccess(true); webSetting.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS); webSetting.setSupportZoom(true); webSetting.setBuiltInZoomControls(true); webSetting.setUseWideViewPort(true); webSetting.setSupportMultipleWindows(true); // webSetting.setLoadWithOverviewMode(true); webSetting.setAppCacheEnabled(true); // webSetting.setDatabaseEnabled(true); webSetting.setDomStorageEnabled(true); webSetting.setGeolocationEnabled(true); webSetting.setAppCacheMaxSize(Long.MAX_VALUE); // webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY); webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND); // webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH); webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE); // this.getSettingsExtension().setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);//extension // settings 的设计}