如何在webview中设置自定义字体
2015-09-28 15:46
501 查看
In your assets/fonts folder, place the desired OTF or TTF font (here MyFont.otf)
[align=left]Create a HTML file that you'll use for the WebView's content, inside the assets folder (here insideassets/demo/my_page.html):[/align]
<html>
<head>
<style type="text/css">
@font-face {
font-family: MyFont;
src: url("file:///android_asset/fonts/MyFont.otf")
}
body {
font-family: MyFont;
font-size: medium;
text-align: justify;
}
</style>
</head>
<body>
Your text can go here! Your text can go here! Your text can go here!
</body>
</html>
[align=left]Load the HTML into the WebView from code:[/align]
webview.loadUrl("file:///android_asset/demo/my_page.html");
Take note that injecting the HTML through loadData() has not worked for me. I'd be curious to hear if anybody can get that working.
需要注意的是,这种方式,只能使用.otf格式的字体文件,不能使用ttf格式的。
[align=left]Create a HTML file that you'll use for the WebView's content, inside the assets folder (here insideassets/demo/my_page.html):[/align]
<html>
<head>
<style type="text/css">
@font-face {
font-family: MyFont;
src: url("file:///android_asset/fonts/MyFont.otf")
}
body {
font-family: MyFont;
font-size: medium;
text-align: justify;
}
</style>
</head>
<body>
Your text can go here! Your text can go here! Your text can go here!
</body>
</html>
[align=left]Load the HTML into the WebView from code:[/align]
webview.loadUrl("file:///android_asset/demo/my_page.html");
Take note that injecting the HTML through loadData() has not worked for me. I'd be curious to hear if anybody can get that working.
需要注意的是,这种方式,只能使用.otf格式的字体文件,不能使用ttf格式的。
相关文章推荐
- Swift 2.0关键字guard
- Android开发读取assert下的txt文件
- Android studio 怎么设置Live Template
- iOS证书整理
- 【Android】Spinner使用
- android中的栈,Task
- 野鸟装备iOS版开发笔记(1.5.0)
- android的性能优化和应用体验改善
- Android开发之Intent跳转到系统应用中的拨号界面、联系人界面、短信界面
- 利用gdb 调试android jni c动态库
- ImageView的属性android:scaleType
- Android_Studio常用插件
- 移动端动画的效率问题
- Android学习笔记-junit测试
- Android中弹出对话框,AlertDialog关键代码
- swifty引用AFNetworking出现clang: error: linker command failed with exit code 1 (use -v to see invocation
- Android中万能适配器
- 关于android中调用系统拍照,返回图片是旋转90度...
- android项目之间的相互引用出现的问题
- Android应用方法数查看,查看size是否超过65k