"Go" Android WebView set the font size of content

Source: Internet
Author: User

Enum for specifying the text size. Smallest is 50% SMALLER are 75% NORMAL is 100% LARGER are 150% largest is 200%
Original: http://www.cnblogs.com/yourancao520/archive/2012/06/14/2548900.html
/**
* WebView
*/
WebView WV;
/**
* Manages settings state for a WebView
*/
WebSettings settings;
/**
* Used to control font size
*/
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;
}

/**
* Set the event of the bottom button
*/
private void Setimageviewclick () {

/**
* Zoom Out button
*/
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
}

}
});

/**
* Zoom In button
*/
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, "");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.