本文整理汇总了Java中com.tencent.smtt.sdk.WebView.getSettings方法的典型用法代码示例。如果您正苦于以下问题:Java WebView.getSettings方法的具体用法?Java WebView.getSettings怎么用?Java WebView.getSettings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.tencent.smtt.sdk.WebView
的用法示例。
在下文中一共展示了WebView.getSettings方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getWebviewAdaption
import com.tencent.smtt.sdk.WebView; //导入方法依赖的package包/类
public void getWebviewAdaption(WebView webView)
{
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setUseWideViewPort(true);//关键点
//启用地理定位
webSettings.setDomStorageEnabled(true);
webSettings.setDatabaseEnabled((Boolean) SPUtils.get(context, "if_4", true));//数据库
webSettings.setGeolocationEnabled((Boolean) SPUtils.get(context, "if_2", true));//地理
webSettings.setUserAgentString("" + SPUtils.get(context, "if_7", "Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en-us) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B206 Safari/7534.48.3 XiaoMi/MiuiBrowser/8.9.4"));//UA
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
webSettings.setDisplayZoomControls(false);
webSettings.setLoadsImagesAutomatically((Boolean) SPUtils.get(context, "if_5", true));//图片
webSettings.setJavaScriptEnabled((Boolean) SPUtils.get(context, "if_1", true)); // 设置支持javascript脚本
webSettings.setAllowFileAccess(true); // 允许访问文件
webSettings.setBuiltInZoomControls(true); // 设置显示缩放按钮
webSettings.setSupportZoom((Boolean) SPUtils.get(context, "if_3", false)); // 支持缩放
webSettings.setLoadWithOverviewMode(true);
DisplayMetrics metrics = new DisplayMetrics();
//getWindowManager().getDefaultDisplay().getMetrics(metrics);
int mDensity = metrics.densityDpi;
// Log.d("maomao", "densityDpi = " + mDensity);
if (mDensity == 240)
{
webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
}
else if (mDensity == 160)
{
webSettings.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
}
else if (mDensity == 120)
{
webSettings.setDefaultZoom(WebSettings.ZoomDensity.CLOSE);
}
else if (mDensity == DisplayMetrics.DENSITY_XHIGH)
{
webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
}
else if (mDensity == DisplayMetrics.DENSITY_TV)
{
webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
}
else
{
webSettings.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
}
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
}
示例2: toSetting
import com.tencent.smtt.sdk.WebView; //导入方法依赖的package包/类
@Override
public WebSettings toSetting(WebView webView) {
this.mWebSettings = webView.getSettings();
mWebSettings.setJavaScriptCanOpenWindowsAutomatically(true);
// webSetting.setLoadWithOverviewMode(true);
// webSetting.setDatabaseEnabled(true);
// webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);
mWebSettings.setPluginState(com.tencent.smtt.sdk.WebSettings.PluginState.ON_DEMAND);
// webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
mWebSettings.setCacheMode(com.tencent.smtt.sdk.WebSettings.LOAD_NO_CACHE);
mWebSettings.setJavaScriptEnabled(true);
mWebSettings.setSupportZoom(true);
mWebSettings.setBuiltInZoomControls(false);
mWebSettings.setSavePassword(false);
if (AgentWebX5Utils.checkNetwork(webView.getContext())) {
//根据cache-control获取数据。
mWebSettings.setCacheMode(com.tencent.smtt.sdk.WebSettings.LOAD_DEFAULT);
} else {
//没网,则从本地获取,即离线加载
mWebSettings.setCacheMode(com.tencent.smtt.sdk.WebSettings.LOAD_CACHE_ELSE_NETWORK);
}
// if(Build.VERSION.SDK_INT >= 21){
// mWebSettings.setMixedContentMode(0);
// webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
// }else if(Build.VERSION.SDK_INT >= 19){
// webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
// }else if(Build.VERSION.SDK_INT < 19){
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
// }
// }
mWebSettings.setRenderPriority(com.tencent.smtt.sdk.WebSettings.RenderPriority.HIGH);
mWebSettings.setTextZoom(100);
mWebSettings.setDatabaseEnabled(true);
mWebSettings.setAppCacheEnabled(true);
mWebSettings.setLoadsImagesAutomatically(true);
mWebSettings.setSupportMultipleWindows(false);
mWebSettings.setBlockNetworkImage(false);//是否阻塞加载网络图片 协议http or https
mWebSettings.setAllowFileAccess(true); //允许加载本地文件html file协议, 这可能会造成不安全 , 建议重写关闭
mWebSettings.setAllowFileAccessFromFileURLs(false); //通过 file url 加载的 Javascript 读取其他的本地文件 .建议关闭
mWebSettings.setAllowUniversalAccessFromFileURLs(false);//允许通过 file url 加载的 Javascript 可以访问其他的源,包括其他的文件和 http,https 等其他的源
mWebSettings.setJavaScriptCanOpenWindowsAutomatically(true);
mWebSettings.setLayoutAlgorithm(com.tencent.smtt.sdk.WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
mWebSettings.setLoadWithOverviewMode(true);
mWebSettings.setUseWideViewPort(true);
mWebSettings.setDomStorageEnabled(true);
mWebSettings.setNeedInitialFocus(true);
mWebSettings.setDefaultTextEncodingName("utf-8");//设置编码格式
mWebSettings.setDefaultFontSize(16);
mWebSettings.setMinimumFontSize(12);//设置 WebView 支持的最小字体大小,默认为 8
mWebSettings.setGeolocationEnabled(true);
//
String dir = AgentWebX5Config.getCachePath(webView.getContext());
Log.i("Info","dir:"+dir+" appcache:"+ AgentWebX5Config.getCachePath(webView.getContext()));
//设置数据库路径 api19 已经废弃,这里只针对 webkit 起作用
mWebSettings.setGeolocationDatabasePath(dir);
mWebSettings.setDatabasePath(dir);
mWebSettings.setAppCachePath(dir);
//适配5.0不允许http和https混合使用情况
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mWebSettings.setMixedContentMode(android.webkit.WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
//缓存文件最大值
mWebSettings.setAppCacheMaxSize(Long.MAX_VALUE);
return this;
}