保持缩放级别中的WebView [英] Keep zoom level in a WebView

查看:109
本文介绍了保持缩放级别中的WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/2959833/webview-how-to-$p$pserve-the-users-zoom-settings-across-sessions">WebView:如何preserve用户的变焦设置在会话?

我正在开发一个简单的Andr​​oid应用程序,它加载初始URL我的WebView里面,那么用户可以自由地放大/缩小和浏览。

I'm developing a simple android app, which loads an initial URL inside my WebView, then the user is free to zoom in/out and navigate.

当用户点击链接时,缩放级别丢失(或重置)并且用户必须放大/缩小再次!这是令人沮丧的用户!我怎么也找不到保存/ preserve当前的缩放。 (我用onScaleChanged事件试过,但现在看来,这是产生用户点击后,才)

When the user taps on a link, the "zoom level" is lost (or reset) and the user has to zoom in/out again! This is frustrating users! I couldn't find how to save/preserve the current zoom. (I've tried using the onScaleChanged event, but it seems it is generated only after the user tapped)

我已经使用,里面onPageFinished解决:

I've solved using, inside onPageFinished:

@Override
public void onPageFinished(WebView webView, String url) {
webView.loadUrl("javascript:(function() { " +  
"document.getElementsByTagName('body')[0].style.zoom='" + yourzoomvariable + "'; })()");
}

非常感谢您的帮助!

Thank you very much for the help!

推荐答案

你有权力,你是显示的HTML?你可以调整缩放比例,也放大了HTML里面的头中的meta标签:

Do you have power over the html you are showing? you could adjust the scaling and zooming also inside the html with a meta tag inside the header:

例如:

<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.5,  maximum-scale=2.0">

编辑:

您也可以在每次加载完成后如下图所示$ C $下改变背景颜色渐变注入的元标记。

You could also inject that metatag on every load finished like below code for changing the background color to a gradient.

public void onPageFinished(WebView view, String url) {



            //styling



            webview.loadUrl("javascript:(function() { " +  
                    "document.getElementsByTagName('body')[0].style.background = '-webkit-gradient(linear, 0% 0%, 0% 100%, from(#143b8a), to(#266af3))'; " + 
                    "})()");  



        }

你也可以请使用放大和zoomout值喜欢这里的<一个解释href="http://stackoverflow.com/questions/5741492/how-to-zoom-in-out-the-content-of-a-webview-programmatically">How放大一个web视图的输入/输出编程的内容吗?的然后,你可以保存有状态,用户将不得不调整它唯一的。

Also you could use the zoomin and zoomout values like explained here How to zoom in/out the content of a WebView programmatically? Then you could save there status and the user would have to adjust it only ones.

这篇关于保持缩放级别中的WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆