Code example for WebView: Displaying web pages

Methods: addJavascriptInterfacegetSettingsloadUrlsetLayoutParamssetVerticalScrollbarOverlay

0
		ctx = this;
		LinearLayout layout = new LinearLayout(this);
		layout.setOrientation(LinearLayout.VERTICAL);
		setContentView(layout);
		// 
		final WebView mWebView = new WebView(this);
		mWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 200));
		mWebView.setVerticalScrollbarOverlay(true);
		final WebSettings settings = mWebView.getSettings();
		settings.setSupportZoom(true);
		//WebView启用Javascript脚本执行 
		settings.setJavaScriptEnabled(true);
		settings.setJavaScriptCanOpenWindowsAutomatically(true);
		//映射Java对象到一个名为”js2java“的Javascript对象上 
		//JavaScript中可以通过"window.js2java"来调用Java对象的方法 
		mWebView.addJavascriptInterface(new JSInvokeClass(), "HTMLOUT");
		mWebView.loadUrl("http://www.baidu.com");
		layout.addView(mWebView);
		// 
		btn = new Button(this);
		btn.setText("show html");
		btn.setOnClickListener(new OnClickListener() {
Stop searching for code, let great code find you!  Add Codota to your java IDE