本文整理匯總了Java中android.webkit.WebView.setInitialScale方法的典型用法代碼示例。如果您正苦於以下問題:Java WebView.setInitialScale方法的具體用法?Java WebView.setInitialScale怎麽用?Java WebView.setInitialScale使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.webkit.WebView
的用法示例。
在下文中一共展示了WebView.setInitialScale方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initWebView
import android.webkit.WebView; //導入方法依賴的package包/類
private static void initWebView(WebView webview) {
webview.setFocusable(true);
webview.setInitialScale(0); // imdb does not look good in fullscreen with anything but this
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (DBG) Log.d(TAG, "shouldOverrideUrlLoading " + url);
return false;
}
});
// Remove 'Mobile' from the user agent to avoid phone-version of IMDB on TV screen...
String userAgent = webview.getSettings().getUserAgentString();
userAgent = userAgent.replace("Mobile", " ");
webview.getSettings().setUserAgentString(userAgent);
}
示例2: onCreateView
import android.webkit.WebView; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater li, ViewGroup vg, Bundle b) {
super.onCreateView(li, vg, b);
Log.i(TAG, "called super...");
View rootView = li.inflate(R.layout.fragment_website, vg, false);
Log.i(TAG, "inflated view...");
mPlayerManualWeb = (WebView) rootView.findViewById(R.id.website_web_view);
Log.i(TAG, "instantiated WebView...");
//1 if portrait 2 if landscape
int orientation = getActivity().getResources().getConfiguration().orientation;
mPlayerManualWeb.setInitialScale(orientation * 100);
mPlayerManualWeb.getSettings().setBuiltInZoomControls(true);
mPlayerManualWeb.loadUrl(mManualUrl);
Log.i(TAG, "performed loadUrl...");
return rootView;
}
示例3: CustomWebViewClient
import android.webkit.WebView; //導入方法依賴的package包/類
/**
* Constructor.
* @param activity Activity to manage intents.
* @param wv <code>WebView</code> where web site will be shown.
* @param url URL address where it is hosted.
* @param urlBase URL main address.
* @param initialScale Initial zoom (0 is default).
*/
@SuppressLint("SetJavaScriptEnabled")
public CustomWebViewClient(Activity activity, WebView wv, String url, String urlBase, UrlCache urlCache, int initialScale) {
this.activity = activity;
this.wv = wv;
this.url = url;
this.urlBase = urlBase;
this.initialScale = initialScale;
this.urlCache = urlCache;
WebSettings settings = wv.getSettings();
settings.setJavaScriptEnabled(true); // We enable Javascript by default, due to it is needed by lots of websites
wv.loadUrl(url);
wv.setInitialScale(initialScale);
}
示例4: onScaleChanged
import android.webkit.WebView; //導入方法依賴的package包/類
@Override
public void onScaleChanged(WebView view, float oldScale, float newScale) {
super.onScaleChanged(view, oldScale, newScale);
if (newScale - oldScale > 7) {
view.setInitialScale((int) (oldScale / newScale * 100)); //異常放大,縮回去。
}
}
示例5: onScaleChanged
import android.webkit.WebView; //導入方法依賴的package包/類
@Override
public void onScaleChanged(WebView view, float oldScale, float newScale) {
if (AgentWebUtils.isOverriedMethod(mWebViewClient, "onScaleChanged", WEBVIEWCLIENTPATH + ".onScaleChanged", WebView.class, float.class, float.class)) {
super.onScaleChanged(view, oldScale, newScale);
return;
}
LogUtils.i(TAG, "onScaleChanged:" + oldScale + " n:" + newScale);
if (newScale - oldScale > CONSTANTS_ABNORMAL_BIG) {
view.setInitialScale((int) (oldScale / newScale * 100));
}
}
示例6: DisplayTemperatureDialog
import android.webkit.WebView; //導入方法依賴的package包/類
@SuppressLint("SetJavaScriptEnabled")
public void DisplayTemperatureDialog(@NonNull String url) {
final Dialog dialog = createDialog();
dialog.setContentView(R.layout.dialog_webview);
TextView titleView = dialog.findViewById(R.id.dialog_title_text_view);
titleView.setText("Temperature Graph");
com.rey.material.widget.Button closeButton = dialog.findViewById(R.id.dialog_button_close);
closeButton.setOnClickListener(v -> dialog.dismiss());
if (!url.startsWith("http://") && !url.startsWith("https://")) {
url = "http://" + url;
}
WebView webview = dialog.findViewById(R.id.dialog_webview);
webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setBuiltInZoomControls(true);
webview.getSettings().setSupportZoom(true);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setLoadWithOverviewMode(true);
webview.setWebViewClient(new WebViewClient());
webview.setInitialScale(100);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(false);
webview.loadUrl(url);
displayDialog(dialog);
}
示例7: onScaleChanged
import android.webkit.WebView; //導入方法依賴的package包/類
@Override
public void onScaleChanged(WebView view, float oldScale, float newScale) {
super.onScaleChanged(view, oldScale, newScale);
if (newScale - oldScale > 7) {
view.setInitialScale((int) (oldScale / newScale * 100)); //異常放大,縮回去。
}
}
示例8: onScaleChanged
import android.webkit.WebView; //導入方法依賴的package包/類
@Override
public void onScaleChanged(WebView view, float oldScale, float newScale) {
super.onScaleChanged(view, oldScale, newScale);
if (newScale - oldScale > 7) {
//異常放大,縮回去。
view.setInitialScale((int) (oldScale / newScale * 100));
}
}
示例9: setUpWebViewDefaults
import android.webkit.WebView; //導入方法依賴的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);
}