Code example for WebView: Displaying web pages

Methods: getSettingsloadUrlsetWebChromeClientsetWebViewClient, setOnKeyListener

0
			String url = String.format(getString(R.string.search_url), word);
			Log.i(TAG, String.format("Loading: %s", url));
			 
			setTitle(String.format(getString(R.string.loading_title), word));
			 
			web = new WebView(this);
			//web.getSettings().setUserAgentString(USER_AGENT); 
			web.getSettings().setJavaScriptEnabled(true);
			 
			// enable progress bar 
			web.setWebChromeClient(new WebChromeClient() {
				public void onProgressChanged(WebView view, int progress) {
					act.setProgress(progress * 100);
					 
					if(progress == 100){ // finished loading
						setTitle(getString(R.string.results));
					} 
				} 
			}); 
			 
			// detect errors 
			web.setWebViewClient(new WebViewClient(){
				@Override 
				public void onReceivedError(WebView view, int errorCode,
						String description, String failingUrl) {
					showErrorToast(description);
					Log.e(TAG, String.format(getString(R.string.err_webclient), description));
				} 
			}); 
			 
			// key listeners 
			web.setOnKeyListener(new OnKeyListener() {
				@Override 
				public boolean onKey(View v, int keyCode, KeyEvent event) {
					// provide back functionality 
					if (keyCode == KeyEvent.KEYCODE_BACK && web.canGoBack()){
						web.goBack();
						return true; 
					} 
					 
					// enable search key. 
					if (keyCode == KeyEvent.KEYCODE_SEARCH){
						//Intent i = new Intent(getApplicationContext(), MainActivity.class); 
						finish();
					} 
					return false; 
				} 
			}); 
			 
			web.loadUrl(url);
			setContentView(web);
		} 
	} 
} 
Connect your IDE to all the code out there  Get Codota for Java