Java Code Examples for android.webkit.WebSettings#setLayoutAlgorithm()
The following examples show how to use
android.webkit.WebSettings#setLayoutAlgorithm() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArticleInfoDetailFragment.java From travelguide with Apache License 2.0 | 6 votes |
@Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); // Fix java.lang.NullPointerException at: // android.view.animation.AnimationUtils.loadAnimation(AnimationUtils.java:71) final Context context = getActivity(); if (shouldAnimate(url, context)) { Utils.fadeOut(context, mProgressContainer); Utils.fadeIn(context, mWebView); } // If picture enable zoom, else disable final WebSettings ws = mWebView.getSettings(); final boolean isPicture = Utils.isPictUrl(url); ws.setBuiltInZoomControls(isPicture); ws.setSupportZoom(isPicture); ws.setLoadWithOverviewMode(isPicture); ws.setLayoutAlgorithm(isPicture ? LayoutAlgorithm.SINGLE_COLUMN : LayoutAlgorithm.NARROW_COLUMNS); ws.setUseWideViewPort(isPicture); }
Example 2
Source File: WebDataActivity.java From YCCustomText with Apache License 2.0 | 6 votes |
public void initWebView(String data) { WebView mWebView = findViewById(R.id.showdiarys); WebSettings settings = mWebView.getSettings(); //settings.setUseWideViewPort(true);//调整到适合webview的大小,不过尽量不要用,有些手机有问题 settings.setLoadWithOverviewMode(true);//设置WebView是否使用预览模式加载界面。 mWebView.setVerticalScrollBarEnabled(false);//不能垂直滑动 mWebView.setHorizontalScrollBarEnabled(false);//不能水平滑动 settings.setTextSize(WebSettings.TextSize.NORMAL);//通过设置WebSettings,改变HTML中文字的大小 settings.setJavaScriptCanOpenWindowsAutomatically(true);//支持通过JS打开新窗口 //设置WebView属性,能够执行Javascript脚本 mWebView.getSettings().setJavaScriptEnabled(true);//设置js可用 mWebView.setWebViewClient(new WebViewClient()); mWebView.addJavascriptInterface(new AndroidJavaScript(getApplication()), "android");//设置js接口 settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);//支持内容重新布局 /****** 22222222 ***********************************************************************/ data = "</Div><head><style>img{ width:100% !important;}</style></head>" + data;//给图片设置一个样式,宽满屏 /****** 2222222222 ***********************************************************************/ mWebView.loadDataWithBaseURL(null, data, "text/html", "utf-8", null); }
Example 3
Source File: BaseWebView.java From RichWebList with Apache License 2.0 | 6 votes |
private void initWebViewSettings() { WebSettings webSetting = this.getSettings(); webSetting.setJavaScriptEnabled(true); webSetting.setJavaScriptCanOpenWindowsAutomatically(true); webSetting.setAllowFileAccess(true); webSetting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); webSetting.setSupportZoom(true); webSetting.setBuiltInZoomControls(true); webSetting.setUseWideViewPort(true); webSetting.setSupportMultipleWindows(true); // webSetting.setLoadWithOverviewMode(true); webSetting.setAppCacheEnabled(true); // webSetting.setDatabaseEnabled(true); webSetting.setDomStorageEnabled(true); webSetting.setGeolocationEnabled(true); webSetting.setAppCacheMaxSize(Long.MAX_VALUE); // webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY); webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND); // webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH); webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE); // this.getSettingsExtension().setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);//extension // settings 的设计 }
Example 4
Source File: WebViewFragment.java From NestedTouchScrollingLayout with MIT License | 6 votes |
private void initWebSettings() { WebSettings settings = this.mWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); settings.setSupportZoom(false); settings.setDisplayZoomControls(false); settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); settings.supportMultipleWindows(); settings.setSupportMultipleWindows(true); settings.setDomStorageEnabled(true); settings.setDatabaseEnabled(true); settings.setAppCacheEnabled(true); settings.setAppCachePath(this.mWebView.getContext().getCacheDir().getAbsolutePath()); settings.setAllowFileAccess(true); settings.setLoadsImagesAutomatically(true); settings.setDefaultTextEncodingName("UTF-8"); }
Example 5
Source File: WebActivity.java From MousePaint with MIT License | 6 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_web); ButterKnife.bind(this); StatusBarCompat.compat(this, getResources().getColor(R.color.black_tran)); mContext = this; mUrl = getIntent().getStringExtra(EXTRA_URL); Log.i("url","url----->"+mUrl); mTitle = getIntent().getStringExtra(EXTRA_TITLE); WebSettings settings = mWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setLoadWithOverviewMode(true); settings.setAppCacheEnabled(true); settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); settings.setSupportZoom(true); mWebView.setWebChromeClient(new ChromeClient()); mWebView.setWebViewClient(new MyWebClient()); mWebView.loadUrl(mUrl); }
Example 6
Source File: WebActivity.java From GankGirl with GNU Lesser General Public License v2.1 | 6 votes |
@Override protected void initView() { mUrl = getIntent().getStringExtra(Constants.EXTRA_URL); mTitle = getIntent().getStringExtra(Constants.EXTRA_TITLE); getToolbar().setTitle(mUrl); WebSettings ws = webView.getSettings(); ws.setJavaScriptEnabled(true); ws.setLoadWithOverviewMode(true); ws.setAppCacheEnabled(true); ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); ws.setSupportZoom(true); webView.setWebChromeClient(new webChromeClient()); webView.setWebViewClient(new webViewClient()); webView.loadUrl(mUrl); }
Example 7
Source File: ByWebView.java From ByWebView with Apache License 2.0 | 5 votes |
@SuppressLint("SetJavaScriptEnabled") private void handleSetting() { WebSettings ws = mWebView.getSettings(); // 保存表单数据 ws.setSaveFormData(true); // 是否应该支持使用其屏幕缩放控件和手势缩放 ws.setSupportZoom(true); ws.setBuiltInZoomControls(true); ws.setDisplayZoomControls(false); // 启动应用缓存 ws.setAppCacheEnabled(true); // 设置缓存模式 ws.setCacheMode(WebSettings.LOAD_DEFAULT); // setDefaultZoom api19被弃用 // 网页内容的宽度自适应屏幕 ws.setLoadWithOverviewMode(true); ws.setUseWideViewPort(true); // 告诉WebView启用JavaScript执行。默认的是false。 ws.setJavaScriptEnabled(true); // 页面加载好以后,再放开图片 ws.setBlockNetworkImage(false); // 使用localStorage则必须打开 ws.setDomStorageEnabled(true); // 排版适应屏幕 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); } else { ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); } // 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); }
Example 8
Source File: CodeWebView.java From OpenHub with GNU General Public License v3.0 | 5 votes |
public void setDiffFileSource(@NonNull String source, boolean wrap) { if (StringUtils.isBlank(source)) return; WebSettings settings = getSettings(); settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING); setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); settings.setSupportZoom(true); settings.setBuiltInZoomControls(true); settings.setDisplayZoomControls(false); String page = HtmlHelper.generateDiffHtml(source, AppUtils.isNightMode(), getCodeBackgroundColor(), wrap); loadPage(page); }
Example 9
Source File: MainActivity.java From chromium-webview-samples with Apache License 2.0 | 5 votes |
private void setUseTextAutoSize(boolean useAlgorithm) { WebSettings settings = mWebView.getSettings(); WebSettings.LayoutAlgorithm layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL; if(useAlgorithm) { layoutAlgorithm = WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING; } settings.setLayoutAlgorithm(layoutAlgorithm); }
Example 10
Source File: WebViewEx.java From FairEmail with GNU General Public License v3.0 | 5 votes |
public WebViewEx(Context context) { super(context); setVerticalScrollBarEnabled(false); setHorizontalScrollBarEnabled(false); setDownloadListener(this); setOnLongClickListener(this); WebSettings settings = getSettings(); settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); settings.setBuiltInZoomControls(true); settings.setDisplayZoomControls(false); settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING); settings.setAllowFileAccess(false); settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean safe_browsing = prefs.getBoolean("safe_browsing", false); settings.setSafeBrowsingEnabled(safe_browsing); } }
Example 11
Source File: WebViewFragment.java From Bitocle with Apache License 2.0 | 5 votes |
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setContentView(R.layout.webview_fragment); setContentEmpty(false); setContentShown(true); View view = getContentView(); webView = (WebView) view.findViewById(R.id.webview); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setLoadsImagesAutomatically(true); webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS.NORMAL); webSettings.setSupportZoom(true); webSettings.setBuiltInZoomControls(true); webSettings.setUseWideViewPort(true); webSettings.setLoadWithOverviewMode(true); webSettings.setDisplayZoomControls(false); SharedPreferences preferences = getActivity().getSharedPreferences(getString(R.string.login_sp), Context.MODE_PRIVATE); String OAuth = preferences.getString(getString(R.string.login_sp_oauth), null); client = new GitHubClient(); client.setOAuth2Token(OAuth); Intent intent = getActivity().getIntent(); owner = intent.getStringExtra(getString(R.string.webview_intent_owner)); name = intent.getStringExtra(getString(R.string.webview_intent_name)); sha = intent.getStringExtra(getString(R.string.webview_intent_sha)); filename = intent.getStringExtra(getString(R.string.webview_intent_title)); task = new WebViewTask(WebViewFragment.this); task.execute(); }
Example 12
Source File: ArticleDetailActivity.java From Awesome-WanAndroid with Apache License 2.0 | 4 votes |
@SuppressLint("SetJavaScriptEnabled") @Override protected void initEventAndData() { mAgentWeb = AgentWeb.with(this) .setAgentWebParent(mWebContent, new LinearLayout.LayoutParams(-1, -1)) .useDefaultIndicator() .setMainFrameErrorView(R.layout.webview_error_view, -1) .createAgentWeb() .ready() .go(articleLink); WebView mWebView = mAgentWeb.getWebCreator().getWebView(); WebSettings mSettings = mWebView.getSettings(); if (mPresenter.getNoImageState()) { mSettings.setBlockNetworkImage(true); } else { mSettings.setBlockNetworkImage(false); } if (mPresenter.getAutoCacheState()) { mSettings.setAppCacheEnabled(true); mSettings.setDomStorageEnabled(true); mSettings.setDatabaseEnabled(true); if (CommonUtils.isNetworkConnected()) { mSettings.setCacheMode(WebSettings.LOAD_DEFAULT); } else { mSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); } } else { mSettings.setAppCacheEnabled(false); mSettings.setDomStorageEnabled(false); mSettings.setDatabaseEnabled(false); mSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); } mSettings.setJavaScriptEnabled(true); mSettings.setSupportZoom(true); mSettings.setBuiltInZoomControls(true); //不显示缩放按钮 mSettings.setDisplayZoomControls(false); //设置自适应屏幕,两者合用 //将图片调整到适合WebView的大小 mSettings.setUseWideViewPort(true); //缩放至屏幕的大小 mSettings.setLoadWithOverviewMode(true); //自适应屏幕 mSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); }
Example 13
Source File: WebSettingsCompat.java From Android_Skin_2.0 with Apache License 2.0 | 4 votes |
@Override public void setLayoutAlgorithm(WebSettings settings, LayoutAlgorithm l) { settings.setLayoutAlgorithm(l); }
Example 14
Source File: SystemWebViewEngine.java From pychat with MIT License | 4 votes |
@SuppressLint({"NewApi", "SetJavaScriptEnabled"}) @SuppressWarnings("deprecation") private void initWebViewSettings() { webView.setInitialScale(0); webView.setVerticalScrollBarEnabled(false); // Enable JavaScript final WebSettings settings = webView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); String manufacturer = android.os.Build.MANUFACTURER; LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer); //We don't save any form data in the application settings.setSaveFormData(false); settings.setSavePassword(false); // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist // while we do this settings.setAllowUniversalAccessFromFileURLs(true); settings.setMediaPlaybackRequiresUserGesture(false); // Enable database // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16 String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath(); settings.setDatabaseEnabled(true); settings.setDatabasePath(databasePath); //Determine whether we're in debug or release mode, and turn on Debugging! ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo(); if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) { enableRemoteDebugging(); } settings.setGeolocationDatabasePath(databasePath); // Enable DOM storage settings.setDomStorageEnabled(true); // Enable built-in geolocation settings.setGeolocationEnabled(true); // Enable AppCache // Fix for CB-2282 settings.setAppCacheMaxSize(5 * 1048576); settings.setAppCachePath(databasePath); settings.setAppCacheEnabled(true); // Fix for CB-1405 // Google issue 4641 String defaultUserAgent = settings.getUserAgentString(); // Fix for CB-3360 String overrideUserAgent = preferences.getString("OverrideUserAgent", null); if (overrideUserAgent != null) { settings.setUserAgentString(overrideUserAgent); } else { String appendUserAgent = preferences.getString("AppendUserAgent", null); if (appendUserAgent != null) { settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent); } } // End CB-3360 IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); if (this.receiver == null) { this.receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { settings.getUserAgentString(); } }; webView.getContext().registerReceiver(this.receiver, intentFilter); } // end CB-1405 }
Example 15
Source File: WebViewActivity.java From NetEasyNews with GNU General Public License v3.0 | 4 votes |
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)); }
Example 16
Source File: WebViewActivity.java From CloudReader with Apache License 2.0 | 4 votes |
@SuppressLint("SetJavaScriptEnabled") private void initWebView() { WebSettings ws = webView.getSettings(); // 网页内容的宽度适配 ws.setLoadWithOverviewMode(true); ws.setUseWideViewPort(true); // 保存表单数据 ws.setSaveFormData(true); // 是否应该支持使用其屏幕缩放控件和手势缩放 ws.setSupportZoom(true); ws.setBuiltInZoomControls(true); ws.setDisplayZoomControls(false); // 启动应用缓存 ws.setAppCacheEnabled(true); // 设置缓存模式 ws.setCacheMode(WebSettings.LOAD_DEFAULT); // 告诉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)); webView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { return handleLongImage(); } }); }
Example 17
Source File: WebViewActivity.java From ByWebView with Apache License 2.0 | 4 votes |
@SuppressLint({"SetJavaScriptEnabled", "AddJavascriptInterface"}) private void initWebView() { WebSettings ws = webView.getSettings(); // 保存表单数据 ws.setSaveFormData(true); // 是否应该支持使用其屏幕缩放控件和手势缩放 ws.setSupportZoom(true); ws.setBuiltInZoomControls(true); ws.setDisplayZoomControls(false); // 启动应用缓存 ws.setAppCacheEnabled(true); // 设置缓存模式 ws.setCacheMode(WebSettings.LOAD_DEFAULT); // setDefaultZoom api19被弃用 // 网页内容的宽度自适应屏幕 ws.setLoadWithOverviewMode(true); ws.setUseWideViewPort(true); // 网页缩放至100,一般的网页达到屏幕宽度效果,个别除外 // webView.setInitialScale(100); // 关掉下滑弧形阴影 // webView.setOverScrollMode(WebView.OVER_SCROLL_NEVER); // 告诉WebView启用JavaScript执行。默认的是false。 ws.setJavaScriptEnabled(true); // 页面加载好以后,再放开图片 ws.setBlockNetworkImage(false); // 使用localStorage则必须打开 ws.setDomStorageEnabled(true); // 排版适应屏幕 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS); } else { ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); } // 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); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { webView.setScrollBarSize(WebTools.dp2px(this, 3)); } mWebChromeClient = new MyWebChromeClient(this); webView.setWebChromeClient(mWebChromeClient); // 与js交互 webView.addJavascriptInterface(new MyJavascriptInterface(this), "injectedObject"); webView.setWebViewClient(new MyWebViewClient(this)); webView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { return handleLongImage(); } }); }
Example 18
Source File: WebViewActivity.java From PLDroidShortVideo with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_web_view); Intent in = getIntent(); web = in.getStringExtra("web"); if (TextUtils.isEmpty(web)) { Toast.makeText(this, "地址为空", Toast.LENGTH_SHORT).show(); } else { WebView webView = (WebView) findViewById(R.id.web); webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { return false;// 返回false } }); WebSettings webSettings = webView.getSettings(); // 让WebView能够执行javaScript webSettings.setJavaScriptEnabled(true); // 让JavaScript可以自动打开windows webSettings.setJavaScriptCanOpenWindowsAutomatically(true); // // 设置缓存 // webSettings.setAppCacheEnabled(true); // // 设置缓存模式,一共有四种模式 // webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); // // 设置缓存路径 // webSettings.setAppCachePath("/storage/emulated/0/Android/data/com.easyar.buddha/files"); // 支持缩放(适配到当前屏幕) webSettings.setSupportZoom(true); // 将图片调整到合适的大小 webSettings.setUseWideViewPort(true); // 支持内容重新布局,一共有四种方式 // 默认的是NARROW_COLUMNS webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); // 设置可以被显示的屏幕控制 webSettings.setDisplayZoomControls(true); // 设置默认字体大小 webSettings.setDefaultFontSize(12); webView.loadUrl(web); } }
Example 19
Source File: ArticleActivity.java From Yuan-WanAndroid with Apache License 2.0 | 4 votes |
@SuppressLint("SetJavaScriptEnabled") @Override protected void initData() { mAgentWeb = AgentWeb.with(this) .setAgentWebParent(mContainerFrameLayout, new LinearLayout.LayoutParams(-1, -1)) .useDefaultIndicator(getResources().getColor(R.color.colorPrimary)) .setOpenOtherPageWays(DefaultWebClient.OpenOtherPageWays.ASK) .createAgentWeb() .ready() .go(mUrl); WebView mWebView = mAgentWeb.getWebCreator().getWebView(); WebSettings mSettings = mWebView.getSettings(); mSettings.setAppCacheEnabled(true); mSettings.setDomStorageEnabled(true); mSettings.setDatabaseEnabled(true); //判断是否为无图模式 if(mPresenter.getNoImgStyleState()){ mSettings.setBlockNetworkImage(true); }else{ mSettings.setBlockNetworkImage(false); } //判断是否为自动缓存模式 if (mPresenter.getAutoCacheState()) { mSettings.setAppCacheEnabled(true); mSettings.setDomStorageEnabled(true); mSettings.setDatabaseEnabled(true); if (CommonUtils.isNetworkConnected(App.getContext())) { mSettings.setCacheMode(WebSettings.LOAD_DEFAULT); } else { mSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); } } else { mSettings.setAppCacheEnabled(false); mSettings.setDomStorageEnabled(false); mSettings.setDatabaseEnabled(false); mSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); } mSettings.setJavaScriptEnabled(true); mSettings.setSupportZoom(true); mSettings.setBuiltInZoomControls(true); //不显示缩放按钮 mSettings.setDisplayZoomControls(false); //设置自适应屏幕,两者合用 //将图片调整到适合WebView的大小 mSettings.setUseWideViewPort(true); //缩放至屏幕的大小 mSettings.setLoadWithOverviewMode(true); //自适应屏幕 mSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); }
Example 20
Source File: PageDetailActivity.java From MaoWanAndoidClient with Apache License 2.0 | 4 votes |
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); // 不缩放 webView.setInitialScale(100); // 告诉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 MyJavascriptInterface(this), "injectedObject"); webView.setWebViewClient(new MyWebViewClient(this)); webView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { return handleLongImage(); } }); }