1

I can't get a WebView to display static HTML. It works in Android 2.3.3 but not in 4.2.2. No similar questions appear relevant, as I'm not using Javascript, HTTPS, and I tried clicking on the view. I tried the documentation 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> 

Emulator running 2.3.3

Imgur

Emulator running 4.2.2

Imgur

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)

6
  • 3
    Not that this is the issue, but shouldn't it be text/html (not texl/html?) Commented May 25, 2013 at 1:09
  • Actually, that could well be the issue. Certainly, WebView can display content via loadData(), as it has for years, such as in this sample app: github.com/commonsguy/cw-omnibus/tree/master/WebKit/Browser3 Commented May 25, 2013 at 1:12
  • @powerj1984 Oh snap! 4 hours on a typo! Curse you Android! Commented May 25, 2013 at 1:16
  • 1
    doh, I guess I'll add that as an answer then :) Commented May 25, 2013 at 1:18
  • 1
    @powerj1984 I found where I copied it from: stackoverflow.com/questions/3150400/… Commented May 25, 2013 at 1:18

1 Answer 1

2

Looks like a typo

texl/html -> text/html

Sign up to request clarification or add additional context in comments.

1 Comment

I found where I copied it from: stackoverflow.com/questions/3150400/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.