Ändern WebView Schrift mit CSS; font-Datei im asset-Ordner. (problem)

Möchte ich ändern WebView schriftart. Es gibt 2 Dateien im "assets" - Ordner. Sie sind:

assets/fonts/DejaVuSans.ttf-und

assets/css/Ergebnis.css

Suchte ich einige Antworten auf StackOverflow und finden eine Lösung, aber es funktioniert nicht. Das Ergebnis.css lädt DejaVuSans.ttf Verwendung von @font-face-Direktive. Dann ist es enthalten in < link > - tag der Daten, die übergeben wird, WebView::loadDataWithBaseURL (Der code ist unten). Das problem ist die CSS-Formatvorlagen arbeitet (der text ist rot), aber die schriftart nicht. Eckige Zeichen erscheint, wenn ich zeige, phonetische Symbole (/'pə:sn/).

String resultText = "<html><head>";
resultText += "<link href=\"css/result.css\"" + " rel=\"stylesheet\" type=\"text/css\" />";
resultText += "<style>" + "@font-face { font-family: \"DejaVuSans\"; " + "" +
"src: url('file:///android_asset/fonts/DejaVuSans.ttf'); }</style>";
resultText += "</head>";
resultText += "<body><p>" + text + "</p>" + "</body></html>";
resultView.loadDataWithBaseURL("file:///android_asset/", resultText, "text/html", "utf-8", null);

Ergebnis.css:

@font-face { 
    font-family: "DejaVuSans"; 
    /*src: url('fonts/DejaVuSans.ttf'); also not work*/ 
    src: url('file:///android_asset/fonts/DejaVuSans.ttf');
}

body {
    color: red;
}

System.aus.println(resultText):

   <html><head><link href="css/result.css" rel="stylesheet" type="text/css" /><style>@font-face { font-family: "DejaVuSans"; src: url('file:///android_asset/fonts/DejaVuSans.ttf'); }</style></head><body><p>person /'pə:sn/</p></body></html>

InformationsquelleAutor Emerald Hieu | 2011-07-17

Schreibe einen Kommentar