Issue
I have a webview in my application where the body text need to be rendered with the "Times New Roman" font. First of all i have put the .ttf file in my Assets folder.

I have modified my style.css file to the folowing:
@font-face {
font-family: "Times New Roman";
src: url("Times-New-Roman.ttf");
}
#body{
font-family: "Times New Roman",Arial,sans-serif;
font-weight: normal;
font-size: 8px;
}
And i create my WebView like this:
WebView webView = new WebView(activity.getApplicationContext());
String child = "<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"><body>Test</body></html>";
webView.loadDataWithBaseURL("file:///android_asset/", child, "text/html", "UTF-8", null);
return webView;
But still when the WebView is rendered its in the default Android font and not Times New Roman. I dont know if it matters but i copied the font form my /Library/Fonts folder on my MacBook and just renamed it with "-" instaid of spaces.
Solution
I figured it out. By removing the # before body in the CSS i got it to work. If someone who knows HTML better than me sees this could you please give a description to why this works?
Answered By - Naknut
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.