开发者

what is arg0 of setDefaultZoom(WebSettings.ZoomDensity.valueOf(arg0))?

I want to zoom the webview to any percentage with the function of

setDefaultZoom(WebSettings.ZoomDensity.valueOf(arg0)

But I do not know how to set the value of arg0 correctly.

I tried to use setInitialScale() to set the zoom percentage, but it does not 开发者_StackOverflow中文版work for some web page.


WebSettings.ZoomDensity is just an enum with the values CLOSE, FAR, and MEDIUM. So to answer your title question: arg0 is one of the strings "CLOSE", "FAR", or "MEDIUM". This would lead to:

setDefaultZoom(WebSettings.ZoomDensity.valueOf("CLOSE"));

But that could be stated more simply as:

setDefaultZoom(WebSettings.ZoomDensity.CLOSE);

And if you used a static import statement such as:

import static android.webkit.WebSettings.ZoomDensity.*;

Then you could simply and elegantly do this:

setDefaultZoom(CLOSE);


According to the documentation, ZoomDensity is an enum for setting the desired density.

So you can set it like so:

setDefaultZoom(WebSettings.ZoomDensity.CLOSE);

setDefaultZoom(WebSettings.ZoomDensity.FAR);

setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);

valueOf() is just a way to convert a string into an enum value:

setDefaultZoom(WebSettings.ZoomDensity.valueOf("CLOSE"));

setDefaultZoom(WebSettings.ZoomDensity.valueOf("FAR"));

setDefaultZoom(WebSettings.ZoomDensity.valueOf("MEDIUM"));


WebSettings.ZoomDensity is an enumeration and the valueOf(String) method is inherited from Enum<E>. The setDefaultZoom(WebSettings.ZoomDensity) method should be called like:

setDefaultZoom(WebSettings.ZoomDensity.CLOSE);

Here is the documentation for the ZoomDensity enum

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜