Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 在webview中显示重音字符大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的应用程序没有正确显示重音字符.我去年调查了这个,但未能找到解决方案.我一直在挖掘,但仍然没有找到解决方案.我提供了一个屏幕截图,显示用户在EditText字段中输入“LondonChâteau”时发生的情况,该字段在单击按钮时加载到WebView中.重音字符“â”未按预期转换.它翻译为“Ãç”,“伦敦Chäteau”.很想得到解决方案,提前谢谢.

我提供了代码来演示:

public class MainActivity extends Activity {

private WebView webView;
private EditText edittext_1;
private Button buttonupdate;

@Override
public void onCreate(Bundle savedInstanceStatE) {
    super.onCreate(savedInstanceStatE);
    setContentView(R.layout.activity_main);

    webView = (WebView) findViewById(R.id.webview_sumMary);
    webView.getSetTings().setJavaScriptEnabled(true);

    edittext_1 = (EditText) findViewById(R.id.editText_1);
    buttonupdate = (Button) findViewById(R.id.button_updatE);

    buttonupdate.setOnClickListener(new View.onClickListener() {
        public void onClick(View v) {
            String s = edittext_1.getText().toString();
            webView.loadData(s,"text/html","utf-8");
        }
    });

}

@Override
public Boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main,menu);
    return true;
}
}

XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://scheR_461_11845@as.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<WebView
    android:id="@+id/webview_sumMary"
    android:layout_width="fill_parent"
    android:layout_height="0px"
    android:layout_weight=".85" />

<LinearLayout
    xmlns:android="http://scheR_461_11845@as.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="0px"
    android:layout_weight=".15" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <EditText
            android:id="@+id/editText_1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="25dp"
            android:hint="text"
            android:minWidth="100dp"
            android:text="" />

        <Button
            android:id="@+id/button_update"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@id/editText_1"
            android:padding="10dp" />
    </RelativeLayout>
</LinearLayout>

</LinearLayout>

@L_674_8@

我一发布就发现了一个有效的建议.我更改了以下行:

webView.loadData(s,"utf-8");

至:

webView.loadDataWithBaseURL(null,s,"utf-8",null);

大佬总结

以上是大佬教程为你收集整理的android – 在webview中显示重音字符全部内容,希望文章能够帮你解决android – 在webview中显示重音字符所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。