[英]WebView won't display static HTML in 4.2.2, but works in 2.3.3
I can't get a WebView to display static HTML. 我无法通过WebView显示静态HTML。 It works in Android 2.3.3 but not in 4.2.2. 它适用于Android 2.3.3,但不适用于4.2.2。 No similar questions appear relevant, as I'm not using Javascript, HTTPS, and I tried clicking on the view. 没有类似的问题相关,因为我没有使用Javascript,HTTPS,并且尝试单击视图。 I tried the documentation http://developer.android.com/reference/android/webkit/WebView.html 我尝试了文档http://developer.android.com/reference/android/webkit/WebView.html
TmpActivity.java TmpActivity.java
public class TmpActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tmp);
WebView webView = (WebView) findViewById(R.id.webView1);
webView.loadData("<html><body>You scored <b>192</b> points.</body></html>","texl/html","UTF-8");
}
activity_tmp.xml activity_tmp.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".TmpActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="20dp" />
</RelativeLayout>
Emulator running 2.3.3 运行2.3.3的模拟器
Emulator running 4.2.2 运行4.2.2的模拟器
There are no errors in the logs. 日志中没有错误。 The only error is 唯一的错误是
05-25 00:56:20.563: E/Trace(4140): error opening trace file: No such file or directory (2) 05-25 00:56:20.563:E / Trace(4140):打开跟踪文件时出错:没有这样的文件或目录(2)
Looks like a typo 看起来像错字
texl/html -> text/html texl / html->文本/ html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.