android webview设置内容的字体大小

Enum for specifying the text size. SMALLEST is 50% SMALLER is 75% NORMAL is 100% LARGER is 150% LARGEST is 200%
原文:http://www.cnblogs.com/yourancao520/archive/2012/06/14/2548900.html
 /**
  * webview
  */
 WebView wv;
 /**
  * Manages settings state for a WebView
  */
 WebSettings settings;
 /**
  * 用来控制字体大小
  */
 int fontSize = 1;

wv = (WebView) findViewById(R.id.webViewContent);
  settings = wv.getSettings();
  settings.setSupportZoom(true);



if (settings.getTextSize() == WebSettings.TextSize.SMALLEST) {
   fontSize = 1;
  } else if (settings.getTextSize() == WebSettings.TextSize.SMALLER) {
   fontSize = 2;
  } else if (settings.getTextSize() == WebSettings.TextSize.NORMAL) {
   fontSize = 3;
  } else if (settings.getTextSize() == WebSettings.TextSize.LARGER) {
   fontSize = 4;
  } else if (settings.getTextSize() == WebSettings.TextSize.LARGEST) {
   fontSize = 5;
  }

/**
     * 设置底部按钮的事件
     */
    private void setImageViewClick() {

        /**
         * 缩小按钮
         */
        imgViewSX.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                fontSize--;

                if (fontSize < 0) {
                    fontSize = 1;
                }
                switch (fontSize) {

                case 1:
                    settings.setTextSize(WebSettings.TextSize.SMALLEST);
                    break;
                case 2:
                    settings.setTextSize(WebSettings.TextSize.SMALLER);
                    break;
                case 3:
                    settings.setTextSize(WebSettings.TextSize.NORMAL);
                    break;
                case 4:
                    settings.setTextSize(WebSettings.TextSize.LARGER);
                    break;
                case 5:
                    settings.setTextSize(WebSettings.TextSize.LARGEST);
                    break;
                }

            }
        });

        /**
         * 放大按钮
         */
        imgViewFD.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                fontSize++;

                if (fontSize > 5) {
                    fontSize = 5;
                }
                switch (fontSize) {

                case 1:
                    settings.setTextSize(WebSettings.TextSize.SMALLEST);
                    break;
                case 2:
                    settings.setTextSize(WebSettings.TextSize.SMALLER);
                    break;
                case 3:
                    settings.setTextSize(WebSettings.TextSize.NORMAL);
                    break;
                case 4:
                    settings.setTextSize(WebSettings.TextSize.LARGER);
                    break;
                case 5:
                    settings.setTextSize(WebSettings.TextSize.LARGEST);
                    break;
                }
            }
        });

final String mimeType = "text/html";
        final String encoding = "UTF-8";

content = getContentFromNewWork(newsId);
wv.loadDataWithBaseURL("", content, mimeType, encoding, "");

【转】android webview设置内容的字体大小,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。