本文整理匯總了Java中android.webkit.WebSettings.setSupportMultipleWindows方法的典型用法代碼示例。如果您正苦於以下問題:Java WebSettings.setSupportMultipleWindows方法的具體用法?Java WebSettings.setSupportMultipleWindows怎麽用?Java WebSettings.setSupportMultipleWindows使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.webkit.WebSettings
的用法示例。
在下文中一共展示了WebSettings.setSupportMultipleWindows方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: init
import android.webkit.WebSettings; //導入方法依賴的package包/類
@SuppressLint("SetJavaScriptEnabled")
private void init(Context context) {
// 頂部顯示的進度條
mProgressBar = new ProgressBar(context, null, android.R.attr.progressBarStyleHorizontal);
mProgressBar.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 7, 0, 0));
Drawable drawable = context.getResources().getDrawable(R.drawable.layer_web_progress_bar);
mProgressBar.setProgressDrawable(drawable);
addView(mProgressBar);
WebSettings webSettings = this.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(true); // 是能放大縮小
webSettings.setUseWideViewPort(true);
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
webSettings.setLoadWithOverviewMode(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setDisplayZoomControls(false);//隱藏
webSettings.setDomStorageEnabled(true);
webSettings.setSupportMultipleWindows(true);
//webSettings.setUseWideViewPort(true);
this.setWebViewClient(mWebViewClientBase);
this.setWebChromeClient(mWebChromeClientBase);
setDownloadListener(new DownloadListener());
this.onResume();
}
示例2: init
import android.webkit.WebSettings; //導入方法依賴的package包/類
private void init() {
final WebSettings setting = getSettings();
setting.setJavaScriptEnabled(true);
setting.setSupportZoom(false);
setting.setSupportMultipleWindows(true);
setting.setSupportZoom(false);
setting.setBuiltInZoomControls(false);
setting.setSupportMultipleWindows(true);
setting.setJavaScriptCanOpenWindowsAutomatically(true);
setting.setDomStorageEnabled(true);
setting.setNeedInitialFocus(false);
setting.setGeolocationEnabled(true);
setting.setAllowFileAccess(true);
setFocusable(true);
setFocusableInTouchMode(true);
}
示例3: initView
import android.webkit.WebSettings; //導入方法依賴的package包/類
@Override
public void initView() {
mIbToolbarMore.setVisibility(View.VISIBLE);
//設置webView
WebSettings settings = mWebView.getSettings();
settings.setRenderPriority(WebSettings.RenderPriority.HIGH);
settings.setSupportMultipleWindows(true);
settings.setJavaScriptEnabled(true);
settings.setSavePassword(false);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setMinimumFontSize(settings.getMinimumLogicalFontSize() + 8);
settings.setAllowFileAccess(false);
settings.setTextSize(WebSettings.TextSize.NORMAL);
mWebView.setVerticalScrollbarOverlay(true);
mWebView.setWebViewClient(new MyWebViewClient());
mWebView.loadUrl(mUrl);
setToolbarTitle(TextUtils.isEmpty(mTitle) ? mWebView.getTitle() : mTitle);
}
示例4: onCreate
import android.webkit.WebSettings; //導入方法依賴的package包/類
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
try {
Bundle extras = getIntent().getExtras();
if (extras == null) {
finish();
return;
}
try {
String string = extras.getString("url");
if (k.a(string)) {
Method method;
super.requestWindowFeature(1);
this.c = new Handler(getMainLooper());
View linearLayout = new LinearLayout(getApplicationContext());
LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -1);
linearLayout.setOrientation(1);
setContentView(linearLayout, layoutParams);
this.a = new WebView(getApplicationContext());
layoutParams.weight = 1.0f;
this.a.setVisibility(0);
linearLayout.addView(this.a, layoutParams);
WebSettings settings = this.a.getSettings();
settings.setUserAgentString(settings.getUserAgentString() + k.c(getApplicationContext()));
settings.setRenderPriority(RenderPriority.HIGH);
settings.setSupportMultipleWindows(true);
settings.setJavaScriptEnabled(true);
settings.setSavePassword(false);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setMinimumFontSize(settings.getMinimumFontSize() + 8);
settings.setAllowFileAccess(false);
settings.setTextSize(TextSize.NORMAL);
this.a.setVerticalScrollbarOverlay(true);
this.a.setWebViewClient(new a());
this.a.setDownloadListener(new a(this));
this.a.loadUrl(string);
if (VERSION.SDK_INT >= 7) {
try {
method = this.a.getSettings().getClass().getMethod("setDomStorageEnabled", new Class[]{Boolean.TYPE});
if (method != null) {
method.invoke(this.a.getSettings(), new Object[]{Boolean.valueOf(true)});
}
} catch (Exception e) {
}
}
try {
method = this.a.getClass().getMethod("removeJavascriptInterface", new Class[0]);
if (method != null) {
method.invoke(this.a, new Object[]{"searchBoxJavaBridge_"});
return;
}
return;
} catch (Exception e2) {
return;
}
}
finish();
} catch (Exception e3) {
finish();
}
} catch (Exception e4) {
finish();
}
}
示例5: onCreate
import android.webkit.WebSettings; //導入方法依賴的package包/類
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
try {
Bundle extras = getIntent().getExtras();
if (extras == null) {
finish();
return;
}
try {
String string = extras.getString("url");
if (k.a(string)) {
Method method;
super.requestWindowFeature(1);
this.c = new Handler(getMainLooper());
Object string2 = extras.getString("cookie");
if (!TextUtils.isEmpty(string2)) {
CookieSyncManager.createInstance(getApplicationContext()).sync();
CookieManager.getInstance().setCookie(string, string2);
CookieSyncManager.getInstance().sync();
}
View linearLayout = new LinearLayout(getApplicationContext());
LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -1);
linearLayout.setOrientation(1);
setContentView(linearLayout, layoutParams);
this.a = new WebView(getApplicationContext());
layoutParams.weight = 1.0f;
this.a.setVisibility(0);
linearLayout.addView(this.a, layoutParams);
WebSettings settings = this.a.getSettings();
settings.setUserAgentString(settings.getUserAgentString() + k.c(getApplicationContext()));
settings.setRenderPriority(RenderPriority.HIGH);
settings.setSupportMultipleWindows(true);
settings.setJavaScriptEnabled(true);
settings.setSavePassword(false);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setMinimumFontSize(settings.getMinimumFontSize() + 8);
settings.setAllowFileAccess(false);
settings.setTextSize(TextSize.NORMAL);
this.a.setVerticalScrollbarOverlay(true);
this.a.setWebViewClient(new a());
this.a.loadUrl(string);
if (VERSION.SDK_INT >= 7) {
try {
method = this.a.getSettings().getClass().getMethod("setDomStorageEnabled", new Class[]{Boolean.TYPE});
if (method != null) {
method.invoke(this.a.getSettings(), new Object[]{Boolean.valueOf(true)});
}
} catch (Exception e) {
}
}
try {
method = this.a.getClass().getMethod("removeJavascriptInterface", new Class[0]);
if (method != null) {
method.invoke(this.a, new Object[]{"searchBoxJavaBridge_"});
return;
}
return;
} catch (Exception e2) {
return;
}
}
finish();
} catch (Exception e3) {
finish();
}
} catch (Exception e4) {
finish();
}
}
示例6: onCreate
import android.webkit.WebSettings; //導入方法依賴的package包/類
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
try {
Bundle extras = getIntent().getExtras();
if (extras == null) {
finish();
return;
}
try {
this.d = extras.getString(b);
String string = extras.getString("params");
if (k.a(string)) {
Method method;
super.requestWindowFeature(1);
this.f = new Handler(getMainLooper());
View linearLayout = new LinearLayout(getApplicationContext());
LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -1);
linearLayout.setOrientation(1);
setContentView(linearLayout, layoutParams);
this.c = new WebView(getApplicationContext());
layoutParams.weight = 1.0f;
this.c.setVisibility(0);
linearLayout.addView(this.c, layoutParams);
WebSettings settings = this.c.getSettings();
settings.setUserAgentString(settings.getUserAgentString() + k.c(getApplicationContext()));
settings.setRenderPriority(RenderPriority.HIGH);
settings.setSupportMultipleWindows(true);
settings.setJavaScriptEnabled(true);
settings.setSavePassword(false);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setMinimumFontSize(settings.getMinimumFontSize() + 8);
settings.setAllowFileAccess(false);
settings.setTextSize(TextSize.NORMAL);
this.c.setVerticalScrollbarOverlay(true);
this.c.setWebViewClient(new b());
this.c.setWebChromeClient(new a());
this.c.setDownloadListener(new a(this));
this.c.loadUrl(string);
if (VERSION.SDK_INT >= 7) {
try {
method = this.c.getSettings().getClass().getMethod("setDomStorageEnabled", new Class[]{Boolean.TYPE});
if (method != null) {
method.invoke(this.c.getSettings(), new Object[]{Boolean.valueOf(true)});
}
} catch (Exception e) {
}
}
try {
method = this.c.getClass().getMethod("removeJavascriptInterface", new Class[0]);
if (method != null) {
method.invoke(this.c, new Object[]{"searchBoxJavaBridge_"});
return;
}
return;
} catch (Exception e2) {
return;
}
}
finish();
} catch (Exception e3) {
finish();
}
} catch (Exception e4) {
finish();
}
}
示例7: initWebView
import android.webkit.WebSettings; //導入方法依賴的package包/類
private void initWebView() {
WebSettings ws = mWebView.getSettings();
// 網頁內容的寬度是否可大於WebView控件的寬度
ws.setLoadWithOverviewMode(false);
// 保存表單數據
ws.setSaveFormData(true);
// 是否應該支持使用其屏幕縮放控件和手勢縮放
ws.setSupportZoom(true);
ws.setBuiltInZoomControls(true);
ws.setDisplayZoomControls(false);
// 啟動應用緩存
ws.setAppCacheEnabled(true);
// 設置緩存模式
ws.setCacheMode(WebSettings.LOAD_DEFAULT);
// setDefaultZoom api19被棄用
// 設置此屬性,可任意比例縮放。
ws.setUseWideViewPort(true);
// 縮放比例 1
mWebView.setInitialScale(1);
// 告訴WebView啟用JavaScript執行。默認的是false。
ws.setJavaScriptEnabled(true);
// 頁麵加載好以後,再放開圖片
ws.setBlockNetworkImage(false);
// 使用localStorage則必須打開
ws.setDomStorageEnabled(true);
// 排版適應屏幕
ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
// WebView是否支持多個窗口。
ws.setSupportMultipleWindows(true);
// webview從5.0開始默認不允許混合模式,https中不能加載http資源,需要設置開啟。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ws.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
/** 設置字體默認縮放大小(改變網頁字體大小,setTextSize api14被棄用)*/
ws.setTextZoom(100);
mWebView.setWebViewClient(new MyWebViewClient());
mWebView.setWebChromeClient(webChromeClient = new MyWebChromeClient());
mWebView.loadUrl(url);
}
示例8: initWebSettings
import android.webkit.WebSettings; //導入方法依賴的package包/類
private void initWebSettings() {
WebSettings settings = mWebView.getSettings();
//支持獲取手勢焦點
mWebView.requestFocusFromTouch();
//支持JS
settings.setJavaScriptEnabled(true);
//支持插件
settings.setPluginState(WebSettings.PluginState.ON);
//設置適應屏幕
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
//支持縮放
settings.setSupportZoom(false);
//隱藏原生的縮放控件
settings.setDisplayZoomControls(false);
//支持內容重新布局
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
settings.supportMultipleWindows();
settings.setSupportMultipleWindows(true);
//設置緩存模式
settings.setDomStorageEnabled(true);
settings.setDatabaseEnabled(true);
settings.setCacheMode(WebSettings.LOAD_DEFAULT);
settings.setAppCacheEnabled(true);
settings.setAppCachePath(mWebView.getContext().getCacheDir().getAbsolutePath());
//設置可訪問文件
settings.setAllowFileAccess(true);
//當webview調用requestFocus時為webview設置節點
settings.setNeedInitialFocus(true);
//支持自動加載圖片
if (Build.VERSION.SDK_INT >= 19) {
settings.setLoadsImagesAutomatically(true);
} else {
settings.setLoadsImagesAutomatically(false);
}
settings.setNeedInitialFocus(true);
//設置編碼格式
settings.setDefaultTextEncodingName("UTF-8");
}
示例9: onCreate
import android.webkit.WebSettings; //導入方法依賴的package包/類
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
try {
Bundle extras = getIntent().getExtras();
if (extras == null) {
finish();
return;
}
try {
String string = extras.getString("url");
if (i.b(string)) {
Method method;
super.requestWindowFeature(1);
this.c = new Handler(getMainLooper());
View linearLayout = new LinearLayout(getApplicationContext());
LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -1);
linearLayout.setOrientation(1);
setContentView(linearLayout, layoutParams);
this.a = new WebView(getApplicationContext());
layoutParams.weight = 1.0f;
this.a.setVisibility(0);
linearLayout.addView(this.a, layoutParams);
WebSettings settings = this.a.getSettings();
settings.setUserAgentString(settings.getUserAgentString() + i.c(getApplicationContext()));
settings.setRenderPriority(RenderPriority.HIGH);
settings.setSupportMultipleWindows(true);
settings.setJavaScriptEnabled(true);
settings.setSavePassword(false);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setMinimumFontSize(settings.getMinimumFontSize() + 8);
settings.setAllowFileAccess(false);
settings.setTextSize(TextSize.NORMAL);
this.a.setVerticalScrollbarOverlay(true);
this.a.setWebViewClient(new a());
this.a.setDownloadListener(new b(this));
this.a.loadUrl(string);
if (VERSION.SDK_INT >= 7) {
try {
method = this.a.getSettings().getClass().getMethod("setDomStorageEnabled", new Class[]{Boolean.TYPE});
if (method != null) {
method.invoke(this.a.getSettings(), new Object[]{Boolean.valueOf(true)});
}
} catch (Exception e) {
}
}
try {
method = this.a.getClass().getMethod("removeJavascriptInterface", new Class[0]);
if (method != null) {
method.invoke(this.a, new Object[]{"searchBoxJavaBridge_"});
method.invoke(this.a, new Object[]{"accessibility"});
method.invoke(this.a, new Object[]{"accessibilityTraversal"});
return;
}
return;
} catch (Exception e2) {
return;
}
}
finish();
} catch (Exception e3) {
finish();
}
} catch (Exception e4) {
finish();
}
}
示例10: onCreate
import android.webkit.WebSettings; //導入方法依賴的package包/類
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
try {
Bundle extras = getIntent().getExtras();
if (extras == null) {
finish();
return;
}
try {
String string = extras.getString("url");
if (i.b(string)) {
Method method;
super.requestWindowFeature(1);
this.c = new Handler(getMainLooper());
Object string2 = extras.getString("cookie");
if (!TextUtils.isEmpty(string2)) {
CookieSyncManager.createInstance(getApplicationContext()).sync();
CookieManager.getInstance().setCookie(string, string2);
CookieSyncManager.getInstance().sync();
}
View linearLayout = new LinearLayout(getApplicationContext());
LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -1);
linearLayout.setOrientation(1);
setContentView(linearLayout, layoutParams);
this.a = new WebView(getApplicationContext());
layoutParams.weight = 1.0f;
this.a.setVisibility(0);
linearLayout.addView(this.a, layoutParams);
WebSettings settings = this.a.getSettings();
settings.setUserAgentString(settings.getUserAgentString() + i.c(getApplicationContext()));
settings.setRenderPriority(RenderPriority.HIGH);
settings.setSupportMultipleWindows(true);
settings.setJavaScriptEnabled(true);
settings.setSavePassword(false);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setMinimumFontSize(settings.getMinimumFontSize() + 8);
settings.setAllowFileAccess(false);
settings.setTextSize(TextSize.NORMAL);
this.a.setVerticalScrollbarOverlay(true);
this.a.setWebViewClient(new a());
this.a.loadUrl(string);
if (VERSION.SDK_INT >= 7) {
try {
method = this.a.getSettings().getClass().getMethod("setDomStorageEnabled", new Class[]{Boolean.TYPE});
if (method != null) {
method.invoke(this.a.getSettings(), new Object[]{Boolean.valueOf(true)});
}
} catch (Exception e) {
}
}
try {
method = this.a.getClass().getMethod("removeJavascriptInterface", new Class[0]);
if (method != null) {
method.invoke(this.a, new Object[]{"searchBoxJavaBridge_"});
method.invoke(this.a, new Object[]{"accessibility"});
method.invoke(this.a, new Object[]{"accessibilityTraversal"});
return;
}
return;
} catch (Exception e2) {
return;
}
}
finish();
} catch (Exception e3) {
finish();
}
} catch (Exception e4) {
finish();
}
}
示例11: onCreate
import android.webkit.WebSettings; //導入方法依賴的package包/類
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
try {
Bundle extras = getIntent().getExtras();
if (extras == null) {
finish();
return;
}
try {
this.d = extras.getString(b);
String string = extras.getString("params");
if (i.b(string)) {
Method method;
super.requestWindowFeature(1);
this.f = new Handler(getMainLooper());
View linearLayout = new LinearLayout(getApplicationContext());
LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -1);
linearLayout.setOrientation(1);
setContentView(linearLayout, layoutParams);
this.c = new WebView(getApplicationContext());
layoutParams.weight = 1.0f;
this.c.setVisibility(0);
linearLayout.addView(this.c, layoutParams);
WebSettings settings = this.c.getSettings();
settings.setUserAgentString(settings.getUserAgentString() + i.c(getApplicationContext()));
settings.setRenderPriority(RenderPriority.HIGH);
settings.setSupportMultipleWindows(true);
settings.setJavaScriptEnabled(true);
settings.setSavePassword(false);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setMinimumFontSize(settings.getMinimumFontSize() + 8);
settings.setAllowFileAccess(false);
settings.setTextSize(TextSize.NORMAL);
this.c.setVerticalScrollbarOverlay(true);
this.c.setWebViewClient(new b());
this.c.setWebChromeClient(new a());
this.c.setDownloadListener(new a(this));
this.c.loadUrl(string);
if (VERSION.SDK_INT >= 7) {
try {
method = this.c.getSettings().getClass().getMethod("setDomStorageEnabled", new Class[]{Boolean.TYPE});
if (method != null) {
method.invoke(this.c.getSettings(), new Object[]{Boolean.valueOf(true)});
}
} catch (Exception e) {
}
}
try {
method = this.c.getClass().getMethod("removeJavascriptInterface", new Class[0]);
if (method != null) {
method.invoke(this.c, new Object[]{"searchBoxJavaBridge_"});
method.invoke(this.c, new Object[]{"accessibility"});
method.invoke(this.c, new Object[]{"accessibilityTraversal"});
return;
}
return;
} catch (Exception e2) {
return;
}
}
finish();
} catch (Exception e3) {
finish();
}
} catch (Exception e4) {
finish();
}
}
示例12: initWebView
import android.webkit.WebSettings; //導入方法依賴的package包/類
private void initWebView() {
mProgressBar.setVisibility(View.VISIBLE);
WebSettings ws = webView.getSettings();
// 網頁內容的寬度是否可大於WebView控件的寬度
ws.setLoadWithOverviewMode(false);
// 保存表單數據
ws.setSaveFormData(true);
// 是否應該支持使用其屏幕縮放控件和手勢縮放
ws.setSupportZoom(true);
ws.setBuiltInZoomControls(true);
ws.setDisplayZoomControls(false);
// 啟動應用緩存
ws.setAppCacheEnabled(true);
// 設置緩存模式
ws.setCacheMode(WebSettings.LOAD_DEFAULT);
// setDefaultZoom api19被棄用
// 設置此屬性,可任意比例縮放。
ws.setUseWideViewPort(true);
// 縮放比例 1
webView.setInitialScale(1);
// 告訴WebView啟用JavaScript執行。默認的是false。
ws.setJavaScriptEnabled(true);
// 頁麵加載好以後,再放開圖片
ws.setBlockNetworkImage(false);
// 使用localStorage則必須打開
ws.setDomStorageEnabled(true);
// 排版適應屏幕
ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
// WebView是否支持多個窗口。
ws.setSupportMultipleWindows(true);
// webview從5.0開始默認不允許混合模式,https中不能加載http資源,需要設置開啟。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ws.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
/** 設置字體默認縮放大小(改變網頁字體大小,setTextSize api14被棄用)*/
ws.setTextZoom(100);
mWebChromeClient = new MyWebChromeClient(this);
webView.setWebChromeClient(mWebChromeClient);
// 與js交互
webView.addJavascriptInterface(new ImageClickInterface(this), "injectedObject");
webView.setWebViewClient(new MyWebViewClient(this));
}
示例13: setUpWebViewDefaults
import android.webkit.WebSettings; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setUpWebViewDefaults(WebView webView) {
WebSettings settings = webView.getSettings();
// 網頁內容的寬度是否可大於WebView控件的寬度
settings.setLoadWithOverviewMode(false);
// 保存表單數據
settings.setSaveFormData(true);
// 是否應該支持使用其屏幕縮放控件和手勢縮放
settings.setSupportZoom(true);
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false);
// 啟動應用緩存
settings.setAppCacheEnabled(true);
// 設置緩存模式
settings.setCacheMode(WebSettings.LOAD_DEFAULT);
// setDefaultZoom api19被棄用
// 設置此屬性,可任意比例縮放。
settings.setUseWideViewPort(true);
// 縮放比例 1
webView.setInitialScale(1);
// 告訴WebView啟用JavaScript執行。默認的是false。
settings.setJavaScriptEnabled(true);
// 頁麵加載好以後,再放開圖片
settings.setBlockNetworkImage(false);
// 使用localStorage則必須打開
settings.setDomStorageEnabled(true);
// 排版適應屏幕
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
// WebView是否支持多個窗口。
settings.setSupportMultipleWindows(true);
// webview從5.0開始默認不允許混合模式,https中不能加載http資源,需要設置開啟。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
/** 設置字體默認縮放大小(改變網頁字體大小,setTextSize api14被棄用)*/
settings.setTextZoom(100);
// Enable remote debugging via chrome://inspect
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
WebView.setWebContentsDebuggingEnabled(true);
}
// AppRTC requires third party cookies to work
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptThirdPartyCookies(webView, true);
}
示例14: initWebView
import android.webkit.WebSettings; //導入方法依賴的package包/類
@SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"})
private void initWebView() {
//進度條設置可見
mProgressBar.setVisibility(View.VISIBLE);
//獲取webView的Setting
WebSettings ws = webView.getSettings();
// 網頁內容的寬度是否可大於WebView控件的寬度
ws.setLoadWithOverviewMode(false);
//保存表單數據
ws.setSaveFormData(true);
// 是否支持屏幕手勢縮放功能
ws.setSupportZoom(true);
ws.setBuiltInZoomControls(true);
//設置true會在WebView上出現點擊放大縮小的按鈕,前提是setSupportZoom為true
ws.setDisplayZoomControls(false);
// 啟動應用緩存
ws.setAppCacheEnabled(true);
ws.setDatabaseEnabled(true);
// 設置緩存模式
if (CheckNetwork.isNetworkConnected(this)) {
ws.setCacheMode(WebSettings.LOAD_DEFAULT);//網絡正常時使用默認緩存策略
} else {
ws.setCacheMode(WebSettings.LOAD_CACHE_ONLY);//網絡不可用時隻使用緩存
}
// setDefaultZoom api19被棄用
// 設置此屬性,可任意比例縮放。
ws.setUseWideViewPort(true);
//縮放比例 1
webView.setInitialScale(1);
// 告訴WebView啟用JavaScript執行。默認的是false。
ws.setJavaScriptEnabled(true);
// 頁麵加載好以後,再放開圖片
ws.setBlockNetworkImage(false);
// 使用localStorage則必須打開,開啟DOM緩存
ws.setDomStorageEnabled(true);
//排版適應屏幕
ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
// WebView是否支持多個窗口。
ws.setSupportMultipleWindows(true);
// webView從5.0開始默認不允許混合模式,https中不能加載http資源,需要設置開啟。
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
ws.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
/** 設置字體默認縮放大小(改變網頁字體大小,setTextSize api14被棄用)*/
ws.setTextZoom(100);
mWebChromeClient = new MyWebChromeClient(this);
//WebChromeClient專門用來輔助WebView處理Javascript
webView.setWebChromeClient(mWebChromeClient);
//與js交互
webView.addJavascriptInterface(new ImageClickInterface(this), "injectedObject");
webView.setWebViewClient(new MyWebViewClient(this));
}
示例15: initWebView
import android.webkit.WebSettings; //導入方法依賴的package包/類
private void initWebView() {
mProgressBar.setVisibility(View.VISIBLE);
WebSettings ws = mWebView.getSettings();
// 網頁內容的寬度是否可大於WebView控件的寬度
ws.setLoadWithOverviewMode(false);
// 保存表單數據
ws.setSaveFormData(true);
// 是否應該支持使用其屏幕縮放控件和手勢縮放
ws.setSupportZoom(true);
ws.setBuiltInZoomControls(true);
ws.setDisplayZoomControls(false);
// 啟動應用緩存
ws.setAppCacheEnabled(true);
// 設置緩存模式
ws.setCacheMode(WebSettings.LOAD_DEFAULT);
// setDefaultZoom api19被棄用
// 設置此屬性,可任意比例縮放。
ws.setUseWideViewPort(true);
// 縮放比例 1
mWebView.setInitialScale(1);
// 告訴WebView啟用JavaScript執行。默認的是false。
ws.setJavaScriptEnabled(true);
// 頁麵加載好以後,再放開圖片
ws.setBlockNetworkImage(false);
// 使用localStorage則必須打開
ws.setDomStorageEnabled(true);
// 排版適應屏幕
ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
// WebView是否支持多個窗口。
ws.setSupportMultipleWindows(true);
// webview從5.0開始默認不允許混合模式,https中不能加載http資源,需要設置開啟。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ws.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
/** 設置字體默認縮放大小(改變網頁字體大小,setTextSize api14被棄用)*/
ws.setTextZoom(100);
mWebChromeClient = new MyWebChromeClient(this);
mWebView.setWebChromeClient(mWebChromeClient);
// 與js交互
mWebView.addJavascriptInterface(new ImageClickInterface(this), "injectedObject");
mWebView.setWebViewClient(new MyWebViewClient(this));
}