webview common configuration settings

 

        webSetting.setAllowContentAccess (true); // whether to allow access to the content in the WebView URL (Content Url) allowed by default

        webSetting.setAllowFileAccess (true); // whether to allow access to the file, the default permission. Note that this only enable or disable access to the file system

        webSetting.setAllowFileAccessFromFileURLs (true); // if allowed to run in a URL context (the context of a file scheme URL) in the JavaScript URL to access content from other environments, in order to ensure safety, should be allowed to

        webSetting.setAppCacheEnabled (true); // Application Cache API is available, the default value of false binding setAppCachePath (String) use.

        String  appCacheDir  =  this .getApplicationContext().getDir("cache", Context.MODE_PRIVATE).getPath();

        webSetting.setAppCachePath (appCacheDir); // set the application cache file path. To make application cache API is available, this method must pass in the path of an application can be written. This method only once, repeated calls are ignored.

        webSetting.setLoadsImagesAutomatically (true); // WebView whether to download pictures resources, the default is true. All image resources if the value of the setting item goes from false content true, WebView display of the references will be downloaded automatically.

        webSetting.setBlockNetworkImage (false); // whether to prohibit from the network (for accessing resources via http and https URI schemes) download pictures resources, the default value is false unless setLoadsImagesAutomatically () returns true, otherwise invalid method

        webSetting.setBuiltInZoomControls (true); // whether to use the built-in zoom mechanism default value is false. Built-in zoom mechanism includes the zoom controls on the screen (to float above the WebView content) and zoom using gestures. By setDisplayZoomControls (boolean) controls whether to display the controls

        // whether to show the zoom controls when using the built-in zoom mechanism, the default value true; webSetting.setDisplayZoomControls (false). See setBuiltInZoomControls (boolean).

        webSetting.setCacheMode (WebSettings.LOAD_DEFAULT); // rewrite using the cache, the default value LOAD_DEFAULT. Cache usage-based navigation type, normal page load, testing the cache, cache contents when needed reproduce. When navigating return, will not reproduce the content, the content will only recover from the cache disk. This method allows the client by specifying LOAD_DEFAULT, LOAD_CACHE_ELSE_NETWORK, LOAD_NO_CACHE or LOAD_CACHE_ONLY which rewrites a behavior.

        webSetting.setDatabaseEnabled (true); // database storage API is available, how to set the default value of false data storage API See setDatabasePath (String) correctly. This setting is valid for all WebView instances of the same process. Note that this can only be modified before any WebView current process of loading the page, because after this node WebView implementation class might change this setting is ignored.


// webSetting.setDatabasePath ( "") // obsolete, database path by the realization (implementation) management, calling this method has no effect.

        webSetting.setDomStorageEnabled (true); // DOM Storage API is available, default false.

        webSetting.setJavaScriptCanOpenWindowsAutomatically (true); // make JavaScript automatically open the window, default false. For JavaScript method window.open ().

        webSetting.setJavaScriptEnabled (true); // set WebView whether to allow execution of JavaScript, default false, are not allowed

        webSetting.setLayoutAlgorithm (WebSettings.LayoutAlgorithm.NORMAL); // set the layout, will cause the WebView re-layout (relayout), the default value NARROW_COLUMNS video screen adaptation

        webSetting.setLoadWithOverviewMode (true); // whether to allow WebView beyond in an overview of the way the page is loaded, default false. That reduced the content to fit the screen width. Provided that take effect when the width exceeds the width WebView control content, for example when () returns true getUseWideViewPort.

        webSetting.setMediaPlaybackRequiresUserGesture (true); // WebView whether the user gesture for media playback, default is true.

        IF (Build.VERSION.SDK_INT> = Build.VERSION_CODES.LOLLIPOP) {
            webSetting.setMixedContentMode (WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); // When a security source (origin) WebView when trying to configure a source load resources from unsafe behavior LOLLIPOP version defaults MIXED_CONTENT_NEVER_ALLOW, WebView choice of the most secure operating mode MIXED_CONTENT_NEVER_ALLOW, do not encourage the use of MIXED_CONTENT_ALWAYS_ALLOW.
        }

        // need to set a node calls requestFocus (int, Android.graphics.Rect) gets the focus, the default is true; webSetting.setNeedInitialFocus (true).

        webSetting.setSaveFormData (true); // WebView whether to save form data, the default value is true.

        webSetting.setSupportMultipleWindows (false); // set WebView supports multiple windows. If set to true, the main program to achieve onCreateWindow (WebView, boolean, boolean, Message), default false. If set to true and does not implement onCreateWindiw listens not jump url in onShouldOverrideUrlLoading

        webSetting.setSupportZoom (true); // WebView supports the zoom controls and gestures on the screen using the zoom, the default value is true. Set setBuiltInZoomControls (boolean) can use special scaling mechanism.

        webSetting.setUseWideViewPort (true); // WebView support of HTML "viewport" tag or use the wide viewport. When set true, the layout of the width of the device is always on the same WebView control irrelevant pixels (device- dependent pixels) width. When the value is true and the page contains viewport tag, the tag uses the specified width.

        webSetting.setUserAgentString ( "android"); // set WebView user agent string. If the string is null or empty, the system will use the default value. Note from KITKAT version, change the user agent will initialize WebView again loaded on page load.

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            WebView.setWebContentsDebuggingEnabled(App.isDebug);
        }

        webSetting.setPluginState (WebSettings.PluginState.ON_DEMAND); // deprecated above API18. The future will not support plug-ins, do not use. Tell WebView enable, disable, or have ready to use (on demand) plug-in, which uses pattern means that if there is a plugin can handle embedded content, displays a placeholder icon, when clicked on. The default value is OFF.

 

Published 19 original articles · won praise 7 · views 30000 +

Guess you like

Origin blog.csdn.net/jiushiwo12340/article/details/104408555