WebView JS 交互
- - ITeye博客WebView加jquery做页面会怎么样呢. // 创建WebView对象. // 把programList添加到js的全局对象window中,. // 这样就可以使用window.programList来获取数据. * 定义js回调java函数. // 绑定键盘的向上,向下按钮事件触发相应的js事件.
以下是使用WebView过程中的部分场景和解决方案
public static synchronized void emulateShiftHeld(WebView view) { try { KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0); shiftPressEvent.dispatch(view); } catch (Exception e) { Log.e(TAG, "Exception in emulateShiftHeld()", e); } } public static synchronized void selectAndCopyText(WebView v) { try { Method m = WebView.class.getMethod("emulateShiftHeld", Boolean.TYPE); m.invoke(v, false); } catch (Exception e) { // fallback emulateShiftHeld(v); }finally{ } }
_webView.setWebViewClient(new WebViewClient(){ public boolean shouldOverrideUrlLoading(WebView view, String url) { TDStockLog.d(TAG, url); if(url.indexOf("&id=")!=-1){ forwardMessageContentActivity(url); }else{ _webView.loadUrl(url); } return true; } });
public void setWebContextDefault(){ if(_webView!=null){ String summary="<html><head></head><body>"+this.getString(R.string.service_not_available)+"</body></html>"; TDStockLog.d(TAG, "content=" + summary); //_webView.getSettings().setBuiltInZoomControls(true); //_webView.getSettings().setJavaScriptEnabled(true); _webView.loadDataWithBaseURL(null, summary, "text/html","utf-8", null); } }
webSettings.setBuiltInZoomControls(true);