Android Question How is a particular typeface (font) specified for use with WebView?

Andris

Active Member
Licensed User
Longtime User
I've loaded a particular font (Montserrat-Regular.ttf) into my assets directory and now I want to specify it within the HTML CSS for a Webview. Is there a simple format to do this? If I construct my HTML like this, it doesn't change the typeface from Arial:

B4X:
    Dim html As StringBuilder
    html.Initialize
    html.Append("<html>")
    html.Append("<head>")
    html.Append("<style>")
    html.Append("h1 {color:black;font-family:'Montserrat-Regular';font-size:20;}")
    html.Append("h2 {color:black;font-family:'Montserrat-Regular';font-size:18;}")
    html.Append("p {color:black;font-family:'Montserrat-Regular';font-size:15;}")
    html.Append("</style>")
    html.Append("</head>")
    html.Append("<body>")
    ...
    ...
    html.Append("</body>")
    html.Append("</html>")

Any suggestions?
 

William Lancee

Well-Known Member
Licensed User
Longtime User
This font is not standard HTML, but you can reference it as follows.
https://www.w3schools.com/howto/tryit.asp?font=Montserrat

B4X:
<!DOCTYPE html>
<html>
<head>
<link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet'>
<style>
body {
    font-family: 'Montserrat';font-size: 22px;
}
</style>
</head>
<body>

<h1>Montserrat</h1>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>
<p>123456790</p>
<p>ABCDEFGHIJKLMNOPQRSTUVWXYZ</p>
<p>abcdefghijklmnopqrstuvwxyz</p>

</body>
</html>
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…