当我在我的Android设备(4.0)中显示WebView
页面时,我注意到éèà这样的特殊字符无法正确显示,就像这样
这是我WebView
的代码。
public class Browser extends Activity{
WebView ourBrow;
String adress;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.browser);
try{
getActionBar().setDisplayShowHomeEnabled(false);
}
catch (Exception e)
{ }
try{
ourBrow = (WebView)findViewById(R.id.wvBrowser);
ourBrow.getSettings().setJavaScriptEnabled(true);
ourBrow.getSettings().setLoadWithOverviewMode(true);
ourBrow.getSettings().setUseWideViewPort(true);
ourBrow.setWebViewClient(new ourViewClient());
ourBrow.setWebChromeClient(new WebChromeClient());
ourBrow.getSettings().setSupportMultipleWindows(true);
String url = null;
Intent intent = getIntent();
try{
if(intent != null) {
if(intent.getExtras() != null) {
url = intent.getExtras().getString("url");
}
}
if(url != null && !url.equals("")) {
ourBrow.loadUrl(url);
}
}catch (Exception e){
}
}catch(Exception e)
{
}
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
if(ourBrow != null) {
ourBrow.stopLoading();
ourBrow.onPause(); //pauses background threads, stops playing sound
ourBrow.pauseTimers(); //pauses the WebViewCore
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_goback, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
// action when setting was selected
case R.id.goback:
ourBrow.stopLoading();
ourBrow.onPause(); //pauses background threads, stops playing sound
ourBrow.pauseTimers(); //pauses the WebViewCore
ourBrow.destroyDrawingCache(); //removes the view from RAM
ourBrow = null;
finish();
break;
default:
break;
}
return true;
}
public class ourViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
//view.loadUrl(url);
view.loadDataWithBaseURL(null, url, "text/html", "utf-8", null);
return true;
}
}
答案 0 :(得分:1)
您可以更改页面编码的设置。例如。
WebSettings settings = myWebView.getSettings();
settings.setDefaultTextEncodingName("utf-8");
您需要确保在请求加载网站之前设置这些。
é应该在utf-8中得到支持,所以我不知道为什么它不应该起作用。
答案 1 :(得分:0)
Webview对变音符号的支持很差。在某些版本中,它们根本不受支持(我记得< 4.2)在其他版本中它们受到部分支持。因此,显示它们最强大的方法是扫描文档以获取变音符号(例如U + 301)并将其替换为图像。