• android webview设置内容的字体大小


    Enum for specifying the text size. SMALLEST is 50% SMALLER is 75% NORMAL is 100% LARGER is 150% LARGEST is 200%

     /**
      * 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, "");
  • 相关阅读:
    super的使用
    Django--自定义 Command 命令
    Django models
    二柱子的编程 四则运算2
    阅读《梦断代码》计划
    随机数计算小学四则运算
    人月神话有感
    软件演化
    软件测试
    软件实现
  • 原文地址:https://www.cnblogs.com/yourancao520/p/2548900.html
Copyright © 2020-2023  润新知