Fixed text size in WebView Android (Lollipop)

陌路散爱 提交于 2019-12-23 11:59:17

问题


I have this simple code in WebView

 <tr><td valign='top' width='30%'><span style='font-size:11px !important;'> @label</span></td><td valign='top' width='2%'><span style='font-size:11px !important;'>:</span></td><td ><span style='font-size:11px !important;word-break:keep-all;'> @val</span></td></tr>

How to have fixed font size of 11px? If I increase/decrease the system font-size in display settings, the above code works perfectly fine in pre-lollipop version. But in Lollipop the font size is changing. I want it to be fixed. I have attached the screen shots for the reference.

Pre-Lollipop

Lollipop

Any help will be greatly appreciated.

P.S : Target SDK Version is 15


回答1:


I solved this.

settings.setTextZoom(100);

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    WebView webview = (WebView) findViewById(R.id.webview);
    WebSettings settings = webview.getSettings();
    settings.setJavaScriptEnabled(true);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH)
        settings.setTextZoom(100);

    webview.loadUrl("http://www.google.co.kr");
}

http://1004lucifer.blogspot.kr/2015/05/android-webview-lollipop.html



来源:https://stackoverflow.com/questions/29816804/fixed-text-size-in-webview-android-lollipop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!