本文整理匯總了Java中android.webkit.WebSettings.setUseWideViewPort方法的典型用法代碼示例。如果您正苦於以下問題:Java WebSettings.setUseWideViewPort方法的具體用法?Java WebSettings.setUseWideViewPort怎麽用?Java WebSettings.setUseWideViewPort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.webkit.WebSettings
的用法示例。
在下文中一共展示了WebSettings.setUseWideViewPort方法的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: initSettings
import android.webkit.WebSettings; //導入方法依賴的package包/類
private void initSettings(){
WebSettings webSettings = this.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setAllowFileAccess(true);
webSettings.setUseWideViewPort(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setSupportZoom(false);
webSettings.setBuiltInZoomControls(false);
webSettings.setDisplayZoomControls(false);
webSettings.setDefaultTextEncodingName("UTF-8");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
webSettings.setAllowFileAccessFromFileURLs(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
}
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptThirdPartyCookies(this,true);
}
setWebViewDefaultCacheMode();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webSettings.setMixedContentMode(
WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
}
setCachePath();
}
示例3: setWebView
import android.webkit.WebSettings; //導入方法依賴的package包/類
private void setWebView() {
WebSettings ws = wvNewContent.getSettings();
ws.setJavaScriptEnabled(true); //支持js
ws.setPluginState(WebSettings.PluginState.ON);//設置是否支持插件
ws.setUseWideViewPort(false); //將圖片調整到適合webview的大小
ws.setSupportZoom(true); //支持縮放
ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); //支持內容重新布局
ws.supportMultipleWindows(); //多窗口
ws.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); //關閉webview中緩存
// cache模式有如下幾種:
// LOAD_DEFAULT: 如果我們應用程序沒有設置任何cachemode, 這個是默認的cache方式。 加載一張網頁會檢查是否有cache,如果有並且沒有過期則使用本地cache,否則從網絡上獲取。
// LOAD_CACHE_ELSE_NETWORK: 使用cache資源,即使過期了也使用,如果沒有cache才從網絡上獲取。
// LOAD_NO_CACHE: 不使用cache 全部從網絡上獲取
// LOAD_CACHE_ONLY: 隻使用cache上的內容
ws.setAllowFileAccess(true); //設置可以訪問文件
ws.setNeedInitialFocus(true); //當webview調用requestFocus時為webview設置節點
ws.setBuiltInZoomControls(true); //設置支持縮放
ws.setJavaScriptCanOpenWindowsAutomatically(true); //支持通過JS打開新窗口
ws.setLoadWithOverviewMode(true); // 縮放至屏幕的大小
ws.setLoadsImagesAutomatically(true); //支持自動加載圖片
}
示例4: onCreate
import android.webkit.WebSettings; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Context of this activity
mContext = this;
// Get main WebView component
mWebView = (WebView) findViewById(R.id.wv_main);
// Get ProgressBar component
mProgress = (ProgressBar) findViewById(R.id.pb_loading);
// Attach clients to mWebView to measure progress and errors
mWebView.setWebViewClient(new WebClient());
mWebView.setWebChromeClient(new ChromeClient());
// Get settings for mWebView
WebSettings settings = mWebView.getSettings();
// The two lines below are to enable interpreting <meta viewport> tag.
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
// Enable JavaScript
settings.setJavaScriptEnabled(true);
// Load AdBlocker
mAdBlocker = new AdBlocker(this);
mAdBlocker.execute();
// Load MangaFox
if (savedInstanceState != null) {
mWebView.restoreState(savedInstanceState);
} else {
mWebView.loadUrl(MANGAFOX_URL);
}
}
示例5: initWebSettings
import android.webkit.WebSettings; //導入方法依賴的package包/類
@SuppressLint("SetJavaScriptEnabled")
public void initWebSettings(WebSettings webSettings){
webSettings.setLoadWithOverviewMode(true);
webSettings.setUseWideViewPort(true);
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(true);
webSettings.setDisplayZoomControls(false);
webSettings.setBuiltInZoomControls(true);
webSettings.setUserAgentString("ios");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
WebView.setWebContentsDebuggingEnabled(true);
}
}
示例6: initializeOptions
import android.webkit.WebSettings; //導入方法依賴的package包/類
@SuppressLint({"SetJavaScriptEnabled", "NewApi"})
public void initializeOptions() {
WebSettings settings = getSettings();
if (VERSION.SDK_INT >= 21) {
CookieManager.getInstance().setAcceptThirdPartyCookies(this, true);
}
settings.setUserAgentString(OtherUtil.getUserAgent(this.mContext));
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setCacheMode(2);
settings.setAllowFileAccess(true);
settings.setDefaultTextEncodingName("utf-8");
settings.setAppCacheEnabled(true);
settings.setGeolocationEnabled(true);
settings.setDatabaseEnabled(true);
settings.setDomStorageEnabled(true);
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false);
settings.setLoadsImagesAutomatically(true);
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
settings.setSaveFormData(true);
CookieManager.getInstance().setAcceptCookie(true);
setLongClickable(false);
setScrollbarFadingEnabled(true);
setScrollBarStyle(0);
setDrawingCacheEnabled(true);
setClickable(true);
setVerticalScrollBarEnabled(false);
setHorizontalScrollBarEnabled(false);
requestFocus();
}
示例7: updateFromPreferences
import android.webkit.WebSettings; //導入方法依賴的package包/類
void updateFromPreferences(SharedPreferences prefs) {
Boolean isDesktop = prefs.getBoolean("pref_desktop_mode", false);
Boolean isJavascript = prefs.getBoolean("pref_javascript", false);
mDraggingPrevented = prefs.getBoolean("pref_prevent_dragging", false);
WebSettings webSettings = getSettings();
webSettings.setUseWideViewPort(isDesktop);
webSettings.setLoadWithOverviewMode(isDesktop);
webSettings.setJavaScriptEnabled(isJavascript);
ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean loadStartUrl = false;
if (mServerURL == null || !mServerURL.equalsIgnoreCase(prefs.getString("pref_url", "!$%"))) {
mServerURL = prefs.getString("pref_url", "");
loadStartUrl = true;
}
if (mStartPanel == null || !mStartPanel.equalsIgnoreCase(prefs.getString("pref_panel", ""))) {
mStartPanel = prefs.getString("pref_panel", "");
loadStartUrl = true;
}
if (mKioskMode != prefs.getBoolean("pref_kiosk_mode", false)) {
mKioskMode = prefs.getBoolean("pref_kiosk_mode", false);
loadStartUrl = true;
}
if (activeNetwork != null && activeNetwork.isConnectedOrConnecting()) {
if (loadStartUrl) {
loadStartUrl();
}
} else {
loadData("<html><body><h1>" + getContext().getString(R.string.waitingNetwork)
+ "</h1><h2>" + getContext().getString(R.string.notConnected)
+ "</h2></body></html>", "text/html", "UTF-8");
}
}
示例8: setWebViewSettings
import android.webkit.WebSettings; //導入方法依賴的package包/類
private void setWebViewSettings() {
WebSettings webSettings = webView.getSettings();
// 打開頁麵時, 自適應屏幕
webSettings.setUseWideViewPort(true); //將圖片調整到適合webview的大小
webSettings.setLoadWithOverviewMode(true); // 縮放至屏幕的大小
// 便頁麵支持縮放
webSettings.setJavaScriptEnabled(true); //支持js
webSettings.setSupportZoom(true); //支持縮放
// webSettings.setBuiltInZoomControls(true); // 放大和縮小的按鈕,容易引發異常 http://blog.csdn.net/dreamer0924/article/details/34082687
webSettings.setAppCacheEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
}
示例9: setupWebView
import android.webkit.WebSettings; //導入方法依賴的package包/類
@SuppressLint("SetJavaScriptEnabled")
private void setupWebView() {
progressBar.spin();
final WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
webSettings.setDomStorageEnabled(true);
webSettings.setGeolocationEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
mWebView.getSettings().setBlockNetworkImage(true);
mWebView.setWebViewClient(webViewClient);
mWebView.requestFocus(View.FOCUS_DOWN);
mWebView.getSettings().setDefaultTextEncodingName("UTF-8");
mWebView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
AlertDialog.Builder b2 = new AlertDialog
.Builder(BrowserActivity.this)
.setTitle(R.string.app_name)
.setMessage(message)
.setPositiveButton("確定", (dialog, which) -> result.confirm());
b2.setCancelable(false);
b2.create();
b2.show();
return true;
}
});
mWebView.loadUrl(url);
}
示例10: onCreate
import android.webkit.WebSettings; //導入方法依賴的package包/類
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_activity_show_result);
webView = (WebView) findViewById(R.id.web_content);
tv = (TextView) findViewById(R.id.tv);
pb = (ProgressBar) findViewById(R.id.progress);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webView.setWebChromeClient(webChromeClient);
webView.setWebViewClient(webViewClient);
Intent intent = getIntent();
if (intent != null) {
resultText = intent.getStringExtra(Constant.EXTRA_RESULT_TEXT_FROM_PIC);
if (Patterns.WEB_URL.matcher(resultText).matches()) {
//是一個web url
tv.setVisibility(View.GONE);
webView.setVisibility(View.VISIBLE);
webView.loadUrl(resultText);
} else {
//不是web url
tv.setVisibility(View.VISIBLE);
webView.setVisibility(View.GONE);
pb.setVisibility(View.GONE);
tv.setText(resultText);
}
}
}
示例11: setDesktopMode
import android.webkit.WebSettings; //導入方法依賴的package包/類
/**
* Force web sites to show their desktop versions
* @param enabled false loads the mobile version
*/
public void setDesktopMode(boolean enabled) {
WebSettings webSettings = getSettings();
String newUserAgent;
if (enabled)
newUserAgent = webSettings.getUserAgentString().replace("Mobile", "eliboM").replace("Android", "diordnA");
else
newUserAgent = webSettings.getUserAgentString().replace("eliboM", "Mobile").replace("diordnA", "Android");
webSettings.setUserAgentString(newUserAgent);
webSettings.setUseWideViewPort(enabled);
webSettings.setLoadWithOverviewMode(enabled);
webSettings.setSupportZoom(enabled);
webSettings.setBuiltInZoomControls(enabled);
}
示例12: setUpWebView
import android.webkit.WebSettings; //導入方法依賴的package包/類
private void setUpWebView() {
WebSettings settings = mWebView.getSettings();
settings.setUseWideViewPort(true);
settings.setBuiltInZoomControls(true);
settings.setLoadWithOverviewMode(true);
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setDomStorageEnabled(true);
settings.setDisplayZoomControls(false);
mWebView.setWebViewClient(new MyWebViewClient());
mWebView.setWebChromeClient(new MyWebChromeClient());
}
示例13: init
import android.webkit.WebSettings; //導入方法依賴的package包/類
private void init() {
WebSettings settings = getSettings();
settings.setUseWideViewPort(true);
settings.setBuiltInZoomControls(true);
settings.setLoadWithOverviewMode(true);
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setDomStorageEnabled(true);
settings.setDisplayZoomControls(false);
setWebViewClient(new WebViewClient());
setWebChromeClient(new WebChromeClient());
}
示例14: 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));
}
示例15: 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));
}