android - WebView 在 4.2.2 中不会显示静态 HTML,但在 2.3.3 中有效

标签 android android-webview android-4.2-jelly-bean

我无法让 WebView 显示静态 HTML。它适用于 Android 2.3.3 但不适用于 4.2.2。没有类似的问题似乎相关,因为我没有使用 Javascript、HTTPS,并且我尝试单击 View 。我尝试了文档 http://developer.android.com/reference/android/webkit/WebView.html

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

<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>

模拟器运行 2.3.3

Imgur

模拟器运行 4.2.2

Imgur

日志中没有错误。唯一的错误是

05-25 00:56:20.563: E/Trace(4140): error opening trace file: No such file or directory (2)

最佳答案

看起来像错字

文本/html -> 文本/html

关于android - WebView 在 4.2.2 中不会显示静态 HTML,但在 2.3.3 中有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16745391/

相关文章:

android - onUpdate 未在小部件中调用,即使我在 onreceive 中看到 android.appwidget.action.APPWIDGET_UPDATE Intent

Android Webview 的 shouldOverrideUrlLoading 方法

javascript - web 中的 firebase google 身份验证不适用于 android app webview

android - Android Jelly Bean 服务中 updateViewLayout 的奇怪行为

android - Nexus 10,前置摄像头预览为黑色(无预览)

android - 服务的 Intent.replaceExtras(bundle) 未按预期工作

Android Studio - 无法解析符号 'firebase'

android - 在使用构建类型和产品风格时如何包含 LeakCanary?

android - 将 webview 嵌入到另一个 View 中

android - 在 Jelly Bean 中向通知添加操作时的灰色按钮