简体   繁体   English

webView.loadUrl显示空白屏幕

[英]webView.loadUrl displays a blank screen

I have to load these Url by using the below code.But finally blank screen displayed as a output.you can check the url link between code at the last line . 我必须使用以下代码加载这些网址 。但是最终,空白屏幕显示为输出。您可以在last line检查代码之间的url链接。

WebPagerLoader.java: WebPagerLoader.java:

public class WebPageLoader extends Activity
{

final Activity activity = this;
private String html;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
        setContentView(R.layout.activity_main);
        WebView webView = (WebView) findViewById(R.id.webview);
        webView.getSettings().setJavaScriptEnabled(true);

        webView.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress)
            {
                activity.setTitle("Loading...");
                activity.setProgress(progress * 100);

                if(progress == 100)
                    activity.setTitle(R.string.app_name);
            }
        });

        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
            {

            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                view.loadUrl(url);
                return true;
            }
        });

  webView.loadUrl("<iframe src=\"http://files.flipsnack.com/iframe/embed.html?hash=fdk843nc&wmode=window&bgcolor=EEEEEE&t=1381431045\" width=\"640\" height=\"385\" seamless=\"seamless\" scrolling=\"no\" frameborder=\"0\" allowtransparency=\"true\"></iframe>";
    }
}       

Manifest: 表现:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.webpageloader"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="19" />

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.webpageloader.WebPageLoader"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

finally I get a blank screen .I doesn't know what I did wrong in webView.loadUrl . 最终我得到了一个blank screen 。我不知道我wrong in webView.loadUrl什么。 I doesn't know how to solve these.Anybody can help me with these problem.Thank You. 我不知道如何解决这些问题。任何人都可以帮助我解决这些问题。谢谢。

Change your 改变你的

webView.loadUrl("<iframe src=\"http://files.flipsnack.com/iframe/embed.html?hash=fdk843nc&wmode=window&bgcolor=EEEEEE&t=1381431045\" width=\"640\" height=\"385\" seamless=\"seamless\" scrolling=\"no\" frameborder=\"0\" allowtransparency=\"true\"></iframe>";

to

webView.loadDataWithBaseURL(null, "<iframe src=\"http://files.flipsnack.com/iframe/embed.html?hash=fdk843nc&wmode=window&bg‌​color=EEEEEE&t=1381431045\" width=\"640\" height=\"385\" seamless=\"seamless\" scrolling=\"no\" frameborder=\"0\" allowtransparency=\"true\"></iframe>", "text/html", "UTF-8", null);

The loadDataWithBaseURL() method takes, among other parameters, the “base URL” to use when resolving relative URLs in the HTML. 在其他参数中, loadDataWithBaseURL()方法采用“基本URL”来解析HTML中的相对URL。 Any relative URL (eg, ) will be interpreted as being relative to the base URL supplied to loadDataWithBaseURL(). 任何相对URL(例如)将被解释为相对于提供给loadDataWithBaseURL()的基本URL。 If you find that you have content that refuses to load properly with loadData(), try loadDataWithBaseURL() with a null base URL, as sometimes that works better, for unknown reasons. 如果发现您的内容拒绝使用loadData()正确加载,请尝试使用具有空基本URL的loadDataWithBaseURL(),因为出于未知原因,有时效果更好。

i have tried and works fine in webviewFragment 我已经尝试过并在webviewFragmentwebviewFragment

 public class WebPageLoader extends Activity
 {

   final Activity activity = this;
   private String html;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
      super.onCreate(savedInstanceState);
      this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
      setContentView(R.layout.activity_main);
      WebView webView = (WebView) findViewById(R.id.webview);
      webView.getSettings().setJavaScriptEnabled(true);

webview.loadUrl("http://files.flipsnack.com/iframe/embed.html?hash=fdk843nc&wmode=window&bgcolor=EEEEEE&t=1381431045");

       webView.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress)
        {
            activity.setTitle("Loading...");
            activity.setProgress(progress * 100);

            if(progress == 100)
                activity.setTitle(R.string.app_name);
        }
     });

     webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
        {

        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url)
        {
            view.loadUrl(url);
            return true;
        }
    });

 }
}       
  • its too much memory consuming file so may its no see proper or blank screen but its work fine but not same as web browser 它的内存消耗过多的文件,因此可能看不到正确的屏幕或黑屏,但工作正常,但与Web浏览器不同

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM