Reprint Please specify the source http://blog.csdn.net/typename/article/details/40302351powered by Miechal Zhao
Overview Android WebView provides display Web pages, but also provides some customization of our application for Web page loading, for example, we can set the currently loaded page in order to reduce the network data cannot display the picture, if the PC URL is accessed on the pad we can provide users with an overview mode of browsing, can provide customized features such as magnifying Web fonts. Android provides some setting class websettings for managing WebView, and WebSettings objects are created when the WebView object is created, with the default settings values attached. WebSettings objects can be obtained by webview.getsettings (). The life cycle of the websettings is the same as the WebView life cycle, and if WebView is destroy then WebSettings should be released, otherwise if you use websettings to continue the operation, Throws an exception illegalstateexception.
1.WebSettings API full Demodulation All functions set with websettings are made asynchronously, so we set a state that does not take effect immediately.
Public synchronized void Setloadsimagesautomatically (Boolean flag)
Sets whether the current WebView needs to load the picture, which controls the state of the entire webview and takes this strategy for all resources. If set to false then access the current URL so that the picture resource will not be loaded. The default value is true;
Public synchronized void Setblocknetworkimage (Boolean flag)
This method is valid when Getloadsimagesautomatically returns TRUE, the default value is: false;
public void Setcachemode (int mode)
A normal web page loading cache will be checked, the content will be re-verified, the first time you visit a Web page, the cache will be stored locally, setting policy can make the page load mode changes, the cache mode is as follows:
Load_default: If our application does not set any Cachemode, this is the default cache mode. Loading a Web page checks to see if there is a cache, and if it does, use the local cache if it does not expire, or get it from the network.
Load_cache_else_network: Use the cache resource, even if it expires, if it is not available from the network without the cache.
Load_no_cache: Do not use CACHE all to get from the network
Load_cache_only: Use only the content on the CACHE.
public void Setloadwithoverviewmode (Boolean overview)
The setting of the overview mode, which defaults to false.
Public synchronized void setjavascriptenabled (Boolean flag)
The default value is False. If we need JavaScript on our web page, we need to turn on this setting, otherwise the page will not load completely.
2.WebSettings WebKit in the implementation of Webseetings API in the Android system version of the changes are not only to increase the API or deprecate some API, but its internal implementation in different versions of the difference, The current mainstream Android version is mainly Android 4.0 or more, analysis of more than 4.0 of the system version of the implementation of Webseetings is divided into three Android 4.0, Android 4.1---4.3,android 4.4. Below is an analysis of the implementation of the above versions of Android:
1) Android 4.0 system is mainly divided into two parts, part of the API layer, the other part of the settings storage location. Settings storage location Most of the setting are eventually set to WebCore Settings.cpp, such as javascriptenable, etc. are stored inside the module according to the module, For example, Cachemode stored in Frameloader. 2) The Android 4.1--4.3 system reconstructs the WebView framework, and the websettings changes accordingly. The middle of the bridge class was introduced WEBSETTINGSCLASSC. Settings storage location Most of the setting is eventually set to WebCore Settings.cpp, such as javascriptenable, and a part of the platform-related storage in the corresponding module of the Webcoresupport layer, For example, on 4.1---4.3 cachemode stored in Webrequestcontext
On Android 4.4 The WebView bottom implementation replaced the chromium, in order to be compatible with the old WebSettings interface, Android 4.4 made the chromium of the bridge class, The main involved websettings related code in contentsettingsadapter,awsettings. And some of the previous versions of the same is the majority of settings or stored in the WebKit Settings.cpp, here is a brief introduction chromium use of the blink rendering engine, and blink from the WebKit is stripped out, Also retained the WebKit parsing and so on. So the directory structure will be different from the Settings.cpp that we saw before, stored in the WebCore directory. Also part of the settings on Android 4.4 is stored on the platform porting layer. Here is an analysis of this setting for Cachemode:
Reference: Http://developer.android.com/reference/packages.html#q=websettingshttps://source.android.com/Android 4.0-- -4.4
Android WebView Development Details (iii)