简体   繁体   中英

How can i change my font size when loading webview?

How can I change my font size in android when I load string data using web view, I don't want it in my java program, want to change font size in my XML files, because it working for both small and tab devices.

viewHolder.web.setBackgroundColor(Color.TRANSPARENT);
viewHolder.webSettings =viewHolder.web.getSettings();
viewHolder.webSettings.setDefaultFontSize(14);

String pish = "<html><head><style type=\"text/css\">@font-face {font-family: MyFont;src: url(\"file:///android_asset/fonts/Regular.ttf\")}body {font-family: MyFont;font-size: medium;color:#000000;text-align: justify;}</style></head><body>";
String description=faqArrayList.get(i).getDescription();
String myHtmlString = pish + description;
viewHolder.web.loadDataWithBaseURL(null,myHtmlString, "text/html", "UTF-8", null);            

I used the code mentioned above in my project.

Try

  1. Add <bool name="isTablet">false</bool> to values/dimens.xml

     <resources> <bool name="isTablet">false</bool> </resources> 
  2. Add <bool name="isTablet">true</bool> to values-sw600dp/dimens.xml

     <resources> <bool name="isTablet">true</bool> </resources> 
  3. Add following code to your activity:

     if (context.getResources ().getBoolean (R.bool.isTablet)) { web.getSettings ().setTextZoom (120); //large font for tablet } else { web.getSettings ().setTextZoom (100); //default for phone } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM