Why does Android WebView display a black screen?

I hit my head against the wall during the day, trying to get WebView to work. Below is the code in the main class:

public class fkyougoogle extends Activity {
    /** Called when the activity is first created. */
 WebView webview;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        webview = (WebView) findViewById(R.id.webview);
        webview.getSettings().setJavaScriptEnabled(true);
        // WORKS
        //webview.loadUrl("http://www.google.com");
        // DOESN'T WORK
        //webview.loadUrl("http://www.theregister.co.uk");
        //webview.loadData("<html><body>hello</body></html>", "text/html", "utf-8");
        //webview.loadDataWithBaseURL("fake://", "<html><body>hello</body></html>", "text/html", "utf-8", "http://www.theregister.co.uk/");

    }
}

This is an example of Google Hello, Webview. If I use WebView and try to access www.google.com, then it works fine. If I try to access any other site, then it does not turn on, including loadData, and it just displays a black screen in the emulator. In the end, I would like to read from a local file.

is included in the manifest tag, and the XML schema is the same as the Hello Webview example.

Did I miss something obvious here ?: (

+5
source share
3 answers

Try to change

android:layout_width="wrap_content"
android:layout_height="wrap_content"

to

android:layout_width="fill_parent"
android:layout_height="fill_parent"

at the top level main.xml LinearLayout

It should look like this:

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

    <WebView 
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />

</LinearLayout>
+7

UTF-8 UTF-8 . http://www.theregister.co.uk - , , , , - /.

, WebView .

0

, WebView , android.permission.INTERNET -.

0

All Articles