farshad f farshad f - 1 year ago 59
Android Question

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

i just used sth like this at the strings.xml file of my android app:


some text

1-the first question is how can i change the size of the text of h4 tag or how can i know what is its default size?
i have changed the default text size of my app in styles.xml to 23sp but for h4 tag i want it to be for example 28sp.but i dont know where to change it.

2-my second question: is it possible to set different textSize for buttons and textviews in the theme for the whole app? i mean i want all of my textviews to have 23sp size and buttons to have 26sp.

Answer Source

If you're using a WebView, you can use CSS to style anything. E.g., to change the style of the <h1> tag, you could use

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
        <title>Your title goes here</title>
        <style type="text/css">
            h1 { font-size: 22px; font-weight: bold; text-align: center; }

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

It is not possible to use CSS in Html.fromHtml(), so you wouldn't be able to use this in a TextView, for example.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download