我将在EditText中获取文本,然后在WebView中显示文本。以下代码适用于ASCII字符。对于非ASCII字符,WebView中的文本变成垃圾字符。来自Android EditText的文本在WebView中变为垃圾字符
String input = mEditText.getText().toString();
String html = makeHTML(input); // append HTML elements and headers including MIME and ENCODING header
mWebView.loadData(html, "text/html", "utf-8");
我以为我在做我的HTML错误,所以我尝试直接在WebView中显示文本而不修改文本。但结果是一样的。
String input = mEditText.getText().toString();
mWebView.loadData(input, "text/html", "utf-8");
Toast
,其显示在的EditText非ASCII文本没有任何问题的makeText()
。
有谁知道答案?
非ASCII字符,你可以给一个或两个字符进行测试。 – rajpara 2012-07-25 02:47:43
日本“新闻”和中文“你好” – Sergio 2012-07-25 06:03:30
我会建议你检查https://github.com/mayooresan/Japs-Attack-Ceylon--Android-App这个项目在webview中包含自定义字体。其他方式我不知道。 – rajpara 2012-07-25 06:11:06