【发布时间】:2016-11-13 12:28:27
【问题描述】:
我想在我的 Android 应用程序中使用自定义字体,TextView 中的自定义字体可以正常工作,但我找不到在 WebView 中添加自定义(unicode)字体的方法,我已经尝试了所有可能的方法但失败了,看看我的代码,看看我是否遗漏了什么。谢谢!
我在资产文件夹中创建了一个带有自定义字体系列的 CSS 文件,并使用 LoadDataWithBaseURL 调用它,但它不起作用。
htmlTextView = (WebView) findViewById(R.id.htmlTextView);
String text = "<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />";
htmlTextView.loadDataWithBaseURL("file:///android_asset/", text, "text/html", "UTF-8", null);
htmlTextView.getSettings().setJavaScriptEnabled(true);
htmlTextView.setBackgroundColor(Color.TRANSPARENT);
htmlTextView.getSettings().setDefaultFontSize(
WebHelper.getWebViewFontSize(this));
CSS 文件:
@font-face {
font-family: 'iskoola pota';
src: url('fonts/iskpota.ttf') format('truetype');
}
【问题讨论】:
标签: java android unicode webview android-studio-2.1