WebView displays a black screen

I'm a little embarrassed to post this, but I can't figure out where I am going wrong. I looked at each example and each and everything looks right for me. That's what I'm doing. I have a list that, when you click on an item, takes you to a WebView that displays some static formatted text associated with this list.

Everything worked for me with TextView, but I wanted to be able to use HTML formatting of the text and computing WebView was the way to go. It is currently assumed to display a general link for testing, but when the viewContent intent begins, it just goes to the black screen. I can go back and select another entry, and also just shows a black screen.

I'm not sure which code you want to see, so the viewSection class file and the viewsection.xml layout.

viewSection.java:

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class viewSection extends Activity {

       /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       WebView wv;

       setContentView(R.layout.viewsection);

       wv = (WebView) findViewById(R.id.wv1);
       wv.loadData("<a href='x'>Hello World! - 1</a>",
                                               "text/html",
                                               "utf-8");
   }
}

viewsection.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:orientation="vertical"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content">
       <WebView android:id="@+id/wv1"
               android:layout_height="wrap_content"
               android:layout_width="fill_parent"
       />
</LinearLayout>
+3
source share
1 answer

You probably want to set android:layout_heightto WebViewon fill_parent. I'm not sure if it supports WebView wrap_content.

EDIT . You want to set the width and height LinearLayoutto fill_parent.

Also, if you use a very lightweight HTML style, you can still use TextView; in the Demos API, an example application on how to do this (i.e. StyledText.java and Link.java ).

+2
source

Source: https://habr.com/ru/post/1730950/


All Articles