XML splash screen & # 8594; Show web view

Thanks for trying to solve my problem!

My app is currently loading a webpage using an Android webview. The disadvantage is that sometimes (with a bad connection) a web page takes more than 10 seconds to load. Is there a way to create some kind of XML splatter loading screen when loading a web page?

Take a look at my code ...

package com.ect;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.CookieSyncManager;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class SomeActivity extends Activity {

    /** Called when the activity is first created. */

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

        //THIS IS WHAT I WANT: setContentView(R.layout.main);

        CookieSyncManager.createInstance(getBaseContext());

        // Let display the progress in the activity title bar, like the
        // browser app does.


        getWindow().requestFeature(Window.FEATURE_PROGRESS);

        WebView webview = new WebView(this);
        setContentView(webview);


        webview.getSettings().setJavaScriptEnabled(true);

        final Activity activity = this;
        webview.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
             // Activities and WebViews measure progress with different scales.
             // The progress meter will automatically disappear when we reach 100%
             activity.setProgress(progress * 1000);
        }
      });

webview.setWebViewClient(new WebViewClient() {

public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
        //Users will be notified in case there an error (i.e. no internet connection)
        Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}

public void onPageFinished(WebView view, String url) {
    CookieSyncManager.getInstance().sync();
}
});

CookieSyncManager.getInstance().startSync();
CookieSyncManager.getInstance().sync();

     //This will load the webpage that we want to see
      webview.loadUrl("http://www.web.com/");

   }
}

This is my code. If you look closely, I made a comment that says: "THIS IS WHAT I WANT: ..."

This comment will cause the main.xml file to be displayed, but if I use this comment, the main.xml file will be displayed, but the webview will never appear ...

How can I display the main.xml file and then (after loading the web view) display the web page?

+5
4

WebViewClient onPageFinished(). webView.setWebViewClient(), WebViewClient, , WebView. onPageFinished(), setContentView(), -, .

, , . http://www.giantflyingsaucer.com/blog/?p=1331

+3

, , . WebViewClient.

+4

You should use the onPageFinished () event.

Here is the official Clickme link

Your main action is to setContentView (R.layout.main); and the onPageFinished () function should setContentView (webview);

+3
source

You can do something like this: in your layout, the root layout (or relative layout) do something like this.

<Framelayout android:layout_height="fill_parent" android:layout_width="fill_parent"
....>

    <Webview android:layout_height="fill_parent" android:layout_width="fill_parent"/>

    <include android:layout_height="fill_parent" android:layout_width="fill_parent"  
    layout="@loadingLayout"/>

</Framelayout>

When the webview completes the download, just change the visibility of the incoming components to Gone.

Hope this helps.

+3
source

All Articles