I have been developing an Android RSS news reader.I want to add two buttons for adjusting the font size when a news is loaded in Webview.Can anyone tell me, how can I create a function for changing the font size of Webview?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A
WebViewhas aWebSettingsobject associated with it. You can get the object by callinggetSettingson yourWebView. TheWebSettingsobject has a method calledsetTextZoom(int)which allows you to set the text size. Theintargument is the percentage zoom and defaults to 100.So, maybe something like this:
And something similar to decrease the font.
edit: I should have mentioned that
setTextZoomandgetTextZoomwere introduced in API 14. If you are targeting prior to that API, you should usesettings.setTextSize(WebSettings.TextSize)in which you pass in one of the WebSettings.TextSize enums (SMALLEST, SMALLER, NORMAL, LARGER, or LARGEST).