Code example for WebView: Displaying web pages

Methods: addJavascriptInterfacegetSettingsloadUrlsetWebChromeClientsetWebViewClient, setDownloadListener, setVerticalScrollBarEnabled

0
		RelativeLayout.LayoutParams webViweLayoutParams = new RelativeLayout.LayoutParams(-1, -1);
		webViweLayoutParams.addRule(2, TOOLBAR_ID);
		RelativeLayout.LayoutParams barLayoutParams = new RelativeLayout.LayoutParams(-1, toolbar_height);
		barLayoutParams.addRule(12);
 
		adWebView = new WebView(this);
		adWebView.setVerticalScrollBarEnabled(false);
 
		LinearLayout barLayout = new LinearLayout(this)
		{ 
			protected void onSizeChanged(int w, int h, int ow, int oh)
			{ 
				setBackgroundDrawable(getBarBackground(h));
			} 
		}; 
    
		barLayout.setId(TOOLBAR_ID);
		barLayout.setOrientation(0);
 
		LinearLayout.LayoutParams btnImgLayoutParams = new LinearLayout.LayoutParams(-2, toolbar_height, 1.0F);
		btnImgLayoutParams.gravity = 16;
 
		setImgBtn(barLayout, btnImgLayoutParams);
 
		relativeLayout.addView(barLayout, barLayoutParams);
		relativeLayout.addView(this.adWebView, webViweLayoutParams);
 
		frameLayout.addView(relativeLayout, webFrameParams);
		frameLayout.addView(this.adWebViewProgressBar, porFrameParams);
		ViewGroup.LayoutParams viewGrLayoutParams = new ViewGroup.LayoutParams(-1, -1);
		addContentView(frameLayout, viewGrLayoutParams);
 
		adWebView.setWebViewClient(new webViewClient());
 
		adLink = getIntent().getExtras().getString("adviewurl");
		if (checkFilter(adLink) != -1) {
			finish();
			return; 
		} 
 
		adWebView.setDownloadListener(new AdviewDownloadListener());
		adWebView.setWebChromeClient(new ProWebChromeClient());
 
		WebSettings webSettings = this.adWebView.getSettings();
		webSettings.setUseWideViewPort(true);
		webSettings.setJavaScriptEnabled(true);
		webSettings.setPluginsEnabled(true);
		adWebView.addJavascriptInterface(new AdViewJsObj(), "local_obj");
		webSettings.setSupportZoom(true);
		adWebView.loadUrl(this.adLink);
		 
	} 
 
	private BitmapDrawable getBarBackground(int height)
	{