Java Code Examples for android.webkit.WebSettings#setDisplayZoomControls()
The following examples show how to use
android.webkit.WebSettings#setDisplayZoomControls() .
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: PstDetailFragment.java From Presentation with Apache License 2.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private void showPresentation(String url) { try { WebSettings settings = getWebView().getSettings(); settings.setBuiltInZoomControls(true); settings.setDisplayZoomControls(false); settings.setAllowFileAccessFromFileURLs(false); settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); getWebView().loadDataWithBaseURL( "file:///android_asset/", String.format(getTemplate(), url), "text/html", "utf-8", null); } catch (RuntimeException e) { Logger.e(e.getMessage()); } }
Example 2
Source File: WebActivity.java From Musicoco with Apache License 2.0 | 6 votes |
private void initWebView() { WebSettings webSettings = webView.getSettings(); // webSettings.setJavaScriptEnabled(true); webSettings.setUseWideViewPort(true); //将图片调整到适合webview的大小 webSettings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小 webSettings.setSupportZoom(true); //支持缩放,默认为true。是下面那个的前提。 webSettings.setBuiltInZoomControls(true); //设置内置的缩放控件。若为false,则该WebView不可缩放 webSettings.setDisplayZoomControls(false); //隐藏原生的缩放控件 webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); //关闭webview中缓存 webSettings.setAllowFileAccess(true); //设置可以访问文件 webSettings.setJavaScriptCanOpenWindowsAutomatically(true); //支持通过JS打开新窗口 webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片 webSettings.setDefaultTextEncodingName("utf-8");//设置编码格式 }
Example 3
Source File: UIHelper.java From KJFrameForAndroid with Apache License 2.0 | 6 votes |
@SuppressLint({ "JavascriptInterface", "SetJavaScriptEnabled" }) public static void initWebView(WebView webView) { WebSettings settings = webView.getSettings(); settings.setDefaultFontSize(15); settings.setJavaScriptEnabled(true); settings.setSupportZoom(true); settings.setBuiltInZoomControls(true); int sysVersion = Build.VERSION.SDK_INT; if (sysVersion >= 11) { settings.setDisplayZoomControls(false); } else { ZoomButtonsController zbc = new ZoomButtonsController(webView); zbc.getZoomControls().setVisibility(View.GONE); } webView.setWebViewClient(UIHelper.getWebViewClient()); }
Example 4
Source File: StoryDetailFragment.java From scanvine-android with MIT License | 5 votes |
@SuppressLint("SetJavaScriptEnabled") private void load(Story story, View rootView) { WebView webView = (WebView) rootView.findViewById(R.id.story_detail); if (isAbout) webView.loadUrl("file:///android_asset/about.html"); else if (story != null) { webView.setWebViewClient(getWebViewClient()); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setLoadWithOverviewMode(true); webSettings.setUseWideViewPort(true); webSettings.setBuiltInZoomControls(true); webSettings.setDisplayZoomControls(false); webSettings.setSupportZoom(true); mCallbacks.showProgress(true); if (downloadManager.downloadExistsFor(getActivity(), story)) { File file = new File(getActivity().getFilesDir(), story.getFilename()); try { String contents = Util.ConvertFileToString(file); JSONObject json = new JSONObject(contents); String html = json.getString("file"); html = html==null ? "" : html; html = html.replace("<iframe", "<!--").replace("</iframe>","-->"); Log.i(""+this, "Got downloaded story of length "+html.length()); webView.loadDataWithBaseURL(story.getHost(), html, "text/html", "utf-8", null);; } catch(Exception ex) { Log.e(""+this, "Couldn't get story from "+file); webView.loadUrl(story.getURL()); } } else webView.loadUrl(story.getURL()); } }
Example 5
Source File: ShinnyTechActivity.java From shinny-futures-android with GNU General Public License v3.0 | 5 votes |
@Override protected void initData() { mBinding = (ActivityShinnyTechBinding) mViewDataBinding; WebSettings settings = mBinding.webView.getSettings(); settings.setDomStorageEnabled(true); settings.setJavaScriptEnabled(true); //设置WebView属性,运行执行js脚本 settings.setUseWideViewPort(true);//将图片调整到适合webView的大小 settings.setLoadWithOverviewMode(true); //自适应屏幕 settings.setBuiltInZoomControls(true); settings.setDisplayZoomControls(false); settings.setSupportZoom(true);//设定支持缩放 settings.setDefaultTextEncodingName("utf-8"); settings.setLoadsImagesAutomatically(true); mBinding.webView.loadUrl("https://www.shinnytech.com/q/");//调用loadUrl方法为WebView加入链接 }
Example 6
Source File: AdBlocksWebViewActivity.java From AdBlockedWebView-Android with MIT License | 5 votes |
@SuppressLint("SetJavaScriptEnabled") private void bindView() { // Toolbar mTvTitle = (TextView) findViewById(R.id.toolbar_tv_title); mTvUrl = (TextView) findViewById(R.id.toolbar_tv_url); findViewById(R.id.toolbar_root).setBackgroundColor(getIntent().getIntExtra(EXTRA_COLOR, Color.BLACK)); mCoordinatorLayout = (CoordinatorLayout) findViewById(R.id.a_web_viewer_coordinatorlayout); mProgressBar = (ProgressBar) findViewById(R.id.a_web_viewer_pb); mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.a_web_viewer_srl); mWebView = (WebView) findViewById(R.id.a_web_viewer_wv); mSwipeRefreshLayout.setOnRefreshListener(this); WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { webSettings.setDisplayZoomControls(false); } webSettings.setBuiltInZoomControls(true); webSettings.setSupportZoom(true); webSettings.setDomStorageEnabled(true); mWebView.setWebChromeClient(new MyWebChromeClient()); mWebView.setWebViewClient(new MyWebViewClient()); mWebView.setDownloadListener(this); mWebView.setOnCreateContextMenuListener(this); mBtnMore = (AppCompatImageButton) findViewById(R.id.toolbar_btn_more); //noinspection ConstantConditions findViewById(R.id.toolbar_btn_close).setOnClickListener(this); //noinspection ConstantConditions mBtnMore.setOnClickListener(this); // PopupWindow initPopupMenu(); }
Example 7
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 8
Source File: NewsWebViewActivity.java From SimpleNews with Apache License 2.0 | 5 votes |
/** * Convenience method to set some generic defaults for a * given WebView */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) private void setUpWebViewDefaults() { WebSettings settings = mWebView.getSettings(); // Enable Javascript settings.setJavaScriptEnabled(true); // Use WideViewport and Zoom out if there is no viewport defined settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); // Enable pinch to zoom without the zoom buttons settings.setBuiltInZoomControls(true); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { // Hide the zoom controls for HONEYCOMB+ settings.setDisplayZoomControls(false); } // Enable remote debugging via chrome://inspect if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } // We set the WebViewClient to ensure links are consumed by the WebView rather // than passed to a browser if it can mWebView.setWebViewClient(new WebViewClient()); mWebView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { setRefreshActionButtonState(progress < 100); } }); mWebView.getSettings().setAppCachePath(getApplicationContext().getCacheDir().getAbsolutePath()); mWebView.getSettings().setAllowFileAccess(true); mWebView.getSettings().setAppCacheEnabled(true); }
Example 9
Source File: CustomWebView.java From letv with Apache License 2.0 | 5 votes |
@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(); }
Example 10
Source File: MainFragment.java From chromium-webview-samples with Apache License 2.0 | 5 votes |
/** * Convenience method to set some generic defaults for a * given WebView * * @param webView */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) private void setUpWebViewDefaults(WebView webView) { WebSettings settings = webView.getSettings(); // Enable Javascript settings.setJavaScriptEnabled(true); // Use WideViewport and Zoom out if there is no viewport defined settings.setUseWideViewPort(true); settings.setLoadWithOverviewMode(true); // Enable pinch to zoom without the zoom buttons settings.setBuiltInZoomControls(true); if(Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) { // Hide the zoom controls for HONEYCOMB+ settings.setDisplayZoomControls(false); } // Enable remote debugging via chrome://inspect if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { WebView.setWebContentsDebuggingEnabled(true); } // We set the WebViewClient to ensure links are consumed by the WebView rather // than passed to a browser if it can mWebView.setWebViewClient(new WebViewClient()); }
Example 11
Source File: MainActivity.java From CacheWebView with MIT License | 5 votes |
private void initSettings() { WebSettings webSettings = mWebView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setAllowFileAccess(true); webSettings.setUseWideViewPort(true); webSettings.setLoadWithOverviewMode(true); webSettings.setSupportZoom(true); 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(); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { webSettings.setMixedContentMode( WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE); } }
Example 12
Source File: WebViewActivity.java From movienow with GNU General Public License v3.0 | 5 votes |
private void initWebSettings() { WebSettings webSettings = webViewT.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setBuiltInZoomControls(true); webSettings.setSupportZoom(true); webSettings.setDisplayZoomControls(false); webSettings.setJavaScriptCanOpenWindowsAutomatically(true); webSettings.setAllowFileAccess(true); webSettings.setDefaultTextEncodingName("UTF-8"); webSettings.setLoadWithOverviewMode(true); webSettings.setUseWideViewPort(true); webSettings.setDomStorageEnabled(true); webSettings.setAppCacheMaxSize(1024 * 1024 * 8); String appCachePath = getApplicationContext().getCacheDir().getAbsolutePath(); webSettings.setAppCachePath(appCachePath); webSettings.setAllowFileAccess(true); webSettings.setAppCacheEnabled(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); } webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int mDensity = metrics.densityDpi; 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); } }
Example 13
Source File: RexxarWebViewCore.java From rexxar-android with MIT License | 5 votes |
@TargetApi(16) @SuppressLint("SetJavaScriptEnabled") protected void setupWebSettings(WebSettings ws) { ws.setAppCacheEnabled(true); WebViewCompatUtils.enableJavaScriptForWebView(getContext(), ws); ws.setJavaScriptEnabled(true); ws.setGeolocationEnabled(true); ws.setBuiltInZoomControls(true); ws.setDisplayZoomControls(false); ws.setAllowFileAccess(true); if (Utils.hasJellyBean()) { ws.setAllowFileAccessFromFileURLs(true); ws.setAllowUniversalAccessFromFileURLs(true); } // enable html cache ws.setDomStorageEnabled(true); ws.setAppCacheEnabled(true); // Set cache size to 8 mb by default. should be more than enough ws.setAppCacheMaxSize(1024 * 1024 * 8); // This next one is crazy. It's the DEFAULT location for your app's cache // But it didn't work for me without this line ws.setAppCachePath("/data/data/" + getContext().getPackageName() + "/cache"); ws.setAllowFileAccess(true); ws.setCacheMode(WebSettings.LOAD_DEFAULT); String ua = ws.getUserAgentString() + " " + Rexxar.getUserAgent(); ws.setUserAgentString(ua); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { ws.setUseWideViewPort(true); } if (Utils.hasLollipop()) { ws.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); } }
Example 14
Source File: WebView.java From unity-ads-android with Apache License 2.0 | 4 votes |
public WebView(Context context) { super(context); WebSettings settings = getSettings(); if(Build.VERSION.SDK_INT >= 16) { settings.setAllowFileAccessFromFileURLs(true); settings.setAllowUniversalAccessFromFileURLs(true); } if (Build.VERSION.SDK_INT >= 19) { try { _evaluateJavascript = android.webkit.WebView.class.getMethod("evaluateJavascript", String.class, ValueCallback.class); } catch(NoSuchMethodException e) { DeviceLog.exception("Method evaluateJavascript not found", e); _evaluateJavascript = null; } } settings.setAppCacheEnabled(false); settings.setBlockNetworkImage(false); settings.setBlockNetworkLoads(false); settings.setBuiltInZoomControls(false); settings.setCacheMode(WebSettings.LOAD_NO_CACHE); settings.setDatabaseEnabled(false); if(Build.VERSION.SDK_INT >= 11) { settings.setDisplayZoomControls(false); } settings.setDomStorageEnabled(false); if(Build.VERSION.SDK_INT >= 11) { settings.setEnableSmoothTransition(false); } settings.setGeolocationEnabled(false); settings.setJavaScriptCanOpenWindowsAutomatically(false); settings.setJavaScriptEnabled(true); settings.setLightTouchEnabled(false); settings.setLoadWithOverviewMode(false); settings.setLoadsImagesAutomatically(true); if(Build.VERSION.SDK_INT >= 17) { settings.setMediaPlaybackRequiresUserGesture(false); } if(Build.VERSION.SDK_INT >= 21) { settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW); } settings.setNeedInitialFocus(true); settings.setPluginState(WebSettings.PluginState.OFF); settings.setRenderPriority(WebSettings.RenderPriority.NORMAL); settings.setSaveFormData(false); settings.setSavePassword(false); settings.setSupportMultipleWindows(false); settings.setSupportZoom(false); settings.setUseWideViewPort(true); setHorizontalScrollBarEnabled(false); setVerticalScrollBarEnabled(false); setInitialScale(0); setBackgroundColor(Color.TRANSPARENT); ViewUtilities.setBackground(this, new ColorDrawable(Color.TRANSPARENT)); setBackgroundResource(0); addJavascriptInterface(new WebViewBridgeInterface(), "webviewbridge"); }
Example 15
Source File: EditAreaView.java From 920-text-editor-v2 with Apache License 2.0 | 4 votes |
public EditAreaView(Context context, AttributeSet attrs) { super(context, attrs); if (L.debug) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setWebContentsDebuggingEnabled(true); } } setLongClickable(false); setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { return true; } }); WebSettings ws = getSettings(); ws.setDefaultZoom(WebSettings.ZoomDensity.FAR); ws.setAllowContentAccess(true); ws.setAllowFileAccess(true); ws.setBuiltInZoomControls(false); ws.setDefaultTextEncodingName("utf-8"); ws.setDisplayZoomControls(false); ws.setSupportZoom(false); ws.setLoadWithOverviewMode(false); ws.setJavaScriptEnabled(true); ws.setAppCacheEnabled(false); ws.setDomStorageEnabled(true); ws.setAppCacheMaxSize(1024*1024*80); ws.setAppCachePath(context.getCacheDir().getPath()); // ws.setAllowFileAccess(true); ws.setCacheMode(WebSettings.LOAD_DEFAULT); addJavascriptInterface(new JavascriptApi(), "AndroidEditor"); setWebViewClient(new EditorViewClient()); setWebChromeClient(new EditorViewChromeClient()); pref = Pref.getInstance(getContext()); ThemeList.Theme theme = pref.getThemeInfo(); boolean isDark = false; if (theme != null) { isDark = theme.isDark; } String html = null; try { InputStream is = getContext().getAssets().open("editor.html"); html = IOUtils.readFile(is, "utf-8"); is.close(); } catch (Exception e) { L.e(e); UIUtils.toast(getContext(), R.string.editor_create_unknown_exception); return; } if (!isDark) html = html.replaceAll("<\\!\\-\\-\\{DARK\\-START\\}\\-\\->[\\w\\W]+?<\\!\\-\\-\\{DARK\\-END\\}\\-\\->", ""); loadDataWithBaseURL("file:///android_asset/", html, "text/html", "utf-8", "file:///android_asset/"); //fix dark theme background spark setBackgroundColor(Color.TRANSPARENT); pref.registerOnSharedPreferenceChangeListener(this); onSharedPreferenceChanged(null, Pref.KEY_FONT_SIZE); onSharedPreferenceChanged(null, Pref.KEY_CURSOR_WIDTH); onSharedPreferenceChanged(null, Pref.KEY_SHOW_LINE_NUMBER); onSharedPreferenceChanged(null, Pref.KEY_WORD_WRAP); onSharedPreferenceChanged(null, Pref.KEY_SHOW_WHITESPACE); onSharedPreferenceChanged(null, Pref.KEY_TAB_SIZE); onSharedPreferenceChanged(null, Pref.KEY_AUTO_INDENT); onSharedPreferenceChanged(null, Pref.KEY_AUTO_CAPITALIZE); onSharedPreferenceChanged(null, Pref.KEY_INSERT_SPACE_FOR_TAB); onSharedPreferenceChanged(null, Pref.KEY_THEME); onSharedPreferenceChanged(null, Pref.KEY_TOUCH_TO_ADJUST_TEXT_SIZE); enableHighlight(pref.isHighlight()); setReadOnly(pref.isReadOnly()); }
Example 16
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 17
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 18
Source File: WebViewActivity.java From Focus with GNU General Public License v3.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_web); ButterKnife.bind(this); setSupportActionBar(toolbar); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); } String url = getIntent().getStringExtra(EXTRA_URL); this.url = url; toolbar.setTitle(url); webLayout = new WebLayout(this); String[] imageUrls = {}; mAgentWeb = AgentWeb.with(this) .setAgentWebParent(container, new LinearLayout.LayoutParams(-1, -1)) .useDefaultIndicator() .setWebChromeClient(mWebChromeClient) .setWebViewClient(mWebViewClient) .setWebLayout(webLayout) .addJavascriptInterface("imagelistener",new MJavascriptInterface(WebViewActivity.this,imageUrls,webView)) .setMainFrameErrorView(R.layout.agentweb_error_page, -1) .setSecurityType(AgentWeb.SecurityType.STRICT_CHECK) .setOpenOtherPageWays(DefaultWebClient.OpenOtherPageWays.ASK)//打开其他应用时,弹窗咨询用户是否前往其他应用 .interceptUnkownUrl() //拦截找不到相关页面的Scheme .createAgentWeb() .ready() // .get(); .go(url); WebSettings webSettings = mAgentWeb.getAgentWebSettings().getWebSettings(); webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);//自适应屏幕 ☆☆ webSettings.setDisplayZoomControls(true); webSettings.setUseWideViewPort(true); webSettings.setUserAgentString("Mozilla/5.0 (Windows Phone 10.0; Android 9.1; Microsoft; Lumia 950 XL Dual SIM; KaiOS; Java) Gecko/68 Firefox/68 SearchCraft/2.8.2 baiduboxapp/4.3.0.10"); // mAgentWeb.getUrlLoader().loadUrl(url); // mAgentWeb.getUrlLoader().loadDataWithBaseURL(url,"<script src=\"https://focus.com/nolimit.js\"></script>",null,"utf-8",null); /*webView.requestDisallowInterceptTouchEvent(false); webView.setWebViewClient(new WebViewClient()); */ /* WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true);*/ // webView.loadUrl(url); // webView.loadData(); //双击顶栏回顶部事件 final GestureDetector gestureDetector1 = new GestureDetector(this,new GestureDetector.SimpleOnGestureListener(){ @Override public boolean onDoubleTap(MotionEvent e) { mAgentWeb.getWebCreator().getWebView().scrollTo(0,0); return super.onDoubleTap(e); } }); toolbar.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { return gestureDetector1.onTouchEvent(motionEvent); } }); }
Example 19
Source File: WebViewActivity.java From Focus with GNU General Public License v3.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_web); ButterKnife.bind(this); setSupportActionBar(toolbar); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); } String url = getIntent().getStringExtra(EXTRA_URL); this.url = url; toolbar.setTitle(url); webLayout = new WebLayout(this); String[] imageUrls = {}; mAgentWeb = AgentWeb.with(this) .setAgentWebParent(container, new LinearLayout.LayoutParams(-1, -1)) .useDefaultIndicator() .setWebChromeClient(mWebChromeClient) .setWebViewClient(mWebViewClient) .setWebLayout(webLayout) .addJavascriptInterface("imagelistener",new MJavascriptInterface(WebViewActivity.this,imageUrls,webView)) .setMainFrameErrorView(R.layout.agentweb_error_page, -1) .setSecurityType(AgentWeb.SecurityType.STRICT_CHECK) .setOpenOtherPageWays(DefaultWebClient.OpenOtherPageWays.ASK)//打开其他应用时,弹窗咨询用户是否前往其他应用 .interceptUnkownUrl() //拦截找不到相关页面的Scheme .createAgentWeb() .ready() // .get(); .go(url); WebSettings webSettings = mAgentWeb.getAgentWebSettings().getWebSettings(); webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);//自适应屏幕 ☆☆ webSettings.setDisplayZoomControls(true); webSettings.setUseWideViewPort(true); webSettings.setUserAgentString("Mozilla/5.0 (Windows Phone 10.0; Android 9.1; Microsoft; Lumia 950 XL Dual SIM; KaiOS; Java) Gecko/68 Firefox/68 SearchCraft/2.8.2 baiduboxapp/4.3.0.10"); // mAgentWeb.getUrlLoader().loadUrl(url); // mAgentWeb.getUrlLoader().loadDataWithBaseURL(url,"<script src=\"https://focus.com/nolimit.js\"></script>",null,"utf-8",null); /*webView.requestDisallowInterceptTouchEvent(false); webView.setWebViewClient(new WebViewClient()); */ /* WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true);*/ // webView.loadUrl(url); // webView.loadData(); //双击顶栏回顶部事件 final GestureDetector gestureDetector1 = new GestureDetector(this,new GestureDetector.SimpleOnGestureListener(){ @Override public boolean onDoubleTap(MotionEvent e) { mAgentWeb.getWebCreator().getWebView().scrollTo(0,0); return super.onDoubleTap(e); } }); toolbar.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { return gestureDetector1.onTouchEvent(motionEvent); } }); }
Example 20
Source File: AppUtils.java From materialistic with Apache License 2.0 | 4 votes |
public static void toggleWebViewZoom(WebSettings webSettings, boolean enabled) { webSettings.setSupportZoom(enabled); webSettings.setBuiltInZoomControls(enabled); webSettings.setDisplayZoomControls(false); }