Logo Icon Logo
A Crowd-sourced Cookbook on Writing Great Android® Apps
GitHub logo Twitter logo OReilly Book Cover Art

Customizing a WebView

In Chapter: Networked Applications
Author: Rachee Singh ('racheesingh')
Published? true
FormatLanguage: WikiFormat


You need to customize the WebView opened by your application.


Using the WebSettings class for accessing inbuilt functions for customizing the browser.


As discussed in the recipe titled Accessing a web page through your Android application, to open a web page in an Android application we use a WebView component. Then to load a URL in the WebView we use:


Now, to customize the browser to suit the user's needs there are multiple actions that can be taken. We need to instantiate the WebSettings class:

WebSettings webSettings = webView.getSettings();

Here are a few things that can be done using WebSettings:

  1. Tell the WebView to block network images:
webSettings.setBlockNetworkImage (true);
  1. Set the default font size in the browser:
  1. Set whether the WebView supports zoom:
  1. Tell the WebView to enable javascript execution:
  1. Store whether the WebView is saving password.
  1. Store whether the WebView is saving form data.

Many more methods of this kind are available. For more information, see the Android developers page on the topic.


If you found this recipe useful, why not buy the book and have the whole collection always at hand?"