How to change the default size of <h1> ... <h7> tags in Android WebView?

I am pointing some HTML text like this in the strings.xml file of my android application:

<string> <h4>title</h4><br/> some text </string> 

1) How to resize text for h4 tag? I changed the default text size for my application in styles.xml to 23sp, but for the h4 tag I want it to be, for example, 28sp.

2) Is it possible to change the text size for buttons and text views in the theme for the entire application? I want all my text images to have size and 23sp buttons for 26sp.

+4
source share
1 answer

If you use WebView, you can use CSS to create something. For example, to change the style of the <h1>, <h2>, <h3> and <form> tags, you can use

 <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Your title goes here</title> <style type="text/css"> h1 { font-size: 28px; font-weight: bold; text-align: center; } h2 { font-size: 24px; font-weight: bold; text-align: center; } h3 { font-size: 22px; text-align: center; } input[type=submit], input[type=button], input[type=reset] { font-size: 110%; } </style> 

There are many options for determining font size: you can use ems, pixels (px), points (pt), percentages (e.g. 120%), etc. You can also generate parts of the CSS style at runtime - - this will allow you to convert from dp / sp units to Android pixels, and then use the calculated pixel value to specify the font size in units of "px".

It is not possible to use CSS in Html.fromHtml (), so you cannot use this in a TextView, for example.

+1
source

All Articles