Android WebView显示一个空白页面

时间:2021-01-28 11:52:01

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

尝试创建一个WebView,但它只显示一个空白/白色页面。我已经跟随了几个例子,他们都说使用这个代码……

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:

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

8 个解决方案

#1


14  

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

您需要启用Javascript (. getsettings (). setjavascript (true))),或者选择不依赖Javascript的Web页面。

#2


3  

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

您必须将权限添加到AndroidManifest中。xml文件。

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

#3


2  

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!

好运!

#4


1  

I found an example that finally worked! :)

我找到了一个最终成功的例子!:)

https://apps-for-android.googlecode.com/svn/trunk/Samples/WebViewDemo/src/com/google/android/webviewdemo/WebViewDemo.java

https://apps-for-android.googlecode.com/svn/trunk/Samples/WebViewDemo/src/com/google/android/webviewdemo/WebViewDemo.java

But the problem was also with the URL, when I tried to go to google.com through my WebView in instantly opened my ordinary browser on my phone... But other URL's worked just fine :)

但问题也出在URL上,当我试图通过WebView进入google。com时,我立刻打开了我手机上的普通浏览器……但是其他的URL运行得很好:)

#5


1  

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

使用webview.setLayerType(WebView。LAYER_TYPE_SOFTWARE,null);方法

#6


0  

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

你可能会被重定向。只要安装一个webviewclient allong与您的webview:)

#7


-3  

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"));

快速和肮脏的解决方案可以是当你的android应用程序开始根据web view设置背景颜色时例如我正在使用黑色的myWebView.setBackgroundColor(Color.parseColor(“#000000”);

#8


-4  

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

如果您尝试加载一个HTTPS URL(例如Foursquare认证URL),请不要忘记调用。

webview.clearSslPreferences();

webview.clearSslPreferences();

before trying to load that

在加载之前

#1


14  

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

您需要启用Javascript (. getsettings (). setjavascript (true))),或者选择不依赖Javascript的Web页面。

#2


3  

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

您必须将权限添加到AndroidManifest中。xml文件。

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

#3


2  

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!

好运!

#4


1  

I found an example that finally worked! :)

我找到了一个最终成功的例子!:)

https://apps-for-android.googlecode.com/svn/trunk/Samples/WebViewDemo/src/com/google/android/webviewdemo/WebViewDemo.java

https://apps-for-android.googlecode.com/svn/trunk/Samples/WebViewDemo/src/com/google/android/webviewdemo/WebViewDemo.java

But the problem was also with the URL, when I tried to go to google.com through my WebView in instantly opened my ordinary browser on my phone... But other URL's worked just fine :)

但问题也出在URL上,当我试图通过WebView进入google。com时,我立刻打开了我手机上的普通浏览器……但是其他的URL运行得很好:)

#5


1  

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

使用webview.setLayerType(WebView。LAYER_TYPE_SOFTWARE,null);方法

#6


0  

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

你可能会被重定向。只要安装一个webviewclient allong与您的webview:)

#7


-3  

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"));

快速和肮脏的解决方案可以是当你的android应用程序开始根据web view设置背景颜色时例如我正在使用黑色的myWebView.setBackgroundColor(Color.parseColor(“#000000”);

#8


-4  

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

如果您尝试加载一个HTTPS URL(例如Foursquare认证URL),请不要忘记调用。

webview.clearSslPreferences();

webview.clearSslPreferences();

before trying to load that

在加载之前