Sara
Sara

Reputation: 3733

Android WebView shows a blank page

Trying to create a WebView but it only shows a blank/white page. I have followed several examples and they all say that work with this code...

Here is my code:

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

public class PostenWebView extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.web_view);
        WebView webview = (WebView)findViewById(R.id.webview);
        webview.loadUrl("http://www.google.com");
    }
}

And here is the web_view.xml:

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

Upvotes: 11

Views: 37691

Answers (8)

alex
alex

Reputation: 71

in my case loading google.com worked but my login page returned a completely white page. Adding this fixed it:

            WebSettings webSettings = webView.getSettings();
            webSettings.setJavaScriptEnabled(true);

            webSettings.setDatabaseEnabled(true);
            webSettings.setDomStorageEnabled(true);
            String databasePath = webView.getContext().getDir("databases", Context.MODE_PRIVATE).getPath();
            webSettings.setDatabasePath(databasePath);

Upvotes: 0

jsancheh
jsancheh

Reputation: 54

It's works fine for me

WebView webView = (WebView)findViewById(R.id.webView);

webView.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return false;
    }
});

webView.loadUrl("http://www.google.com");

Good Luck!

Upvotes: 3

Jaya
Jaya

Reputation: 1019

Use webview.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); method

Upvotes: 3

Ayreon
Ayreon

Reputation: 5

if you try to load a HTTPS URL (e.g. Foursquare authentication URL) do not forget to call

webview.clearSslPreferences();

before trying to load that

Upvotes: -4

umar
umar

Reputation: 3133

The quick and dirty solution can be when your android app get started set the background colour according to web view eg i am using black colour so myWebView.setBackgroundColor(Color.parseColor("#000000"));

Upvotes: -3

Abhinava
Abhinava

Reputation: 1030

You might be getting redirected.. just install a webviewclient allong with you web view :)

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1007584

You need to enable Javascript (.getSettings().setJavaScriptEnabled(true)), or choose a Web page that does not rely upon Javascript.

Upvotes: 16

Pentium10
Pentium10

Reputation: 208042

You have to add the permission to your AndroidManifest.xml file.

<uses-permission
        android:name="android.permission.INTERNET"></uses-permission>

Upvotes: 4

Related Questions