如何在 webview 中显示数据库中的缅甸字体
How to show Myanmar font from database in webview
我在数据库中存储缅甸字体。当我通过 webview 显示缅甸字体时,它们显示以下内容。如何更改我的代码?请帮助我。
ပရá'á€á± (ပရá' + အá€á³) = အá,ွá€...္ ... ာá‹
These are my codes.
dstory = (WebView) findViewById(R.id.dstory);
String data=result.getString(3);
dstory.loadData(data , "text/html", "utf-8");
尝试将字体添加到您的资产文件夹,然后通过 CSS
将其添加到您的 WebView
你的代码应该从资产目录加载
webView.loadDataWithBaseURL("file:///android_asset/", data, "text/html", "UTF-8", null);
你的 CSS 应该是
@font-face {
font-family: 'my_font';
src: url('my_font.ttf');
}
@Muthu 谢谢你advice.Now我明白了。
在css文件中,
@font-face {
font-family: 'ZawgyiOne2008';
src: url('file:///android_asset/ZawgyiOne2008.ttf');
}
body{
font-family: ZawgyiOne2008; width: 100%;
background-color: transparent;
padding: 0px;
}
在我的DetailActivity.java,到link css用的满html.
WebView view = (WebView)findViewById(R.id.webView1);
final String mimeType = "text/html";
final String encoding = "UTF-8";
String html =
"<html><head><LINK href=\"file:///android_asset/bootstrap.css\" type=\"text/css\" rel=\"stylesheet\"/></head><body><H1 class='label'>A simple HTML page</H1>" +
"<input type='text' class='input-large' required='true' id='cname' name='cname'/>" +
"<input type='text'/>" +
"<p>The quick brown fox jumps over the lazy dog</p></body></html>";
view.loadDataWithBaseURL("", html, mimeType, encoding, "");
要显示数据库中的缅甸字体,请使用字符串替换。
String old="%@";
String newstr=html.replace(old, data);
我在数据库中存储缅甸字体。当我通过 webview 显示缅甸字体时,它们显示以下内容。如何更改我的代码?请帮助我。
ပရá'á€á± (ပရá' + အá€á³) = အá,ွá€...္ ... ာá‹
These are my codes.
dstory = (WebView) findViewById(R.id.dstory);
String data=result.getString(3);
dstory.loadData(data , "text/html", "utf-8");
尝试将字体添加到您的资产文件夹,然后通过 CSS
将其添加到您的 WebView你的代码应该从资产目录加载
webView.loadDataWithBaseURL("file:///android_asset/", data, "text/html", "UTF-8", null);
你的 CSS 应该是
@font-face {
font-family: 'my_font';
src: url('my_font.ttf');
}
@Muthu 谢谢你advice.Now我明白了。
在css文件中,
@font-face {
font-family: 'ZawgyiOne2008';
src: url('file:///android_asset/ZawgyiOne2008.ttf');
}
body{
font-family: ZawgyiOne2008; width: 100%;
background-color: transparent;
padding: 0px;
}
在我的DetailActivity.java,到link css用的满html.
WebView view = (WebView)findViewById(R.id.webView1);
final String mimeType = "text/html";
final String encoding = "UTF-8";
String html =
"<html><head><LINK href=\"file:///android_asset/bootstrap.css\" type=\"text/css\" rel=\"stylesheet\"/></head><body><H1 class='label'>A simple HTML page</H1>" +
"<input type='text' class='input-large' required='true' id='cname' name='cname'/>" +
"<input type='text'/>" +
"<p>The quick brown fox jumps over the lazy dog</p></body></html>";
view.loadDataWithBaseURL("", html, mimeType, encoding, "");
要显示数据库中的缅甸字体,请使用字符串替换。
String old="%@";
String newstr=html.replace(old, data);