Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

javascript - Loading a WebView URL before splashscreen finishes

I followed this tutorial https://www.youtube.com/watch?v=QD9nhyWX-gs to make an animated splashscreen which is just my logo doing one 360? spin which text and a background below it after the spin it opens a webview which displays google.com.au but it has that white background while it loads the webpage and i need it to load the webpage beforehand in the splashscreen and keep the animation repeating till the website it loaded, the code is fairly simple its just a rotating imageview.

Just tried:

public class WelcomeActivity extends Activity {
WebView web;
ImageView imageView;

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

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

    web.setWebViewClient(new myWebClient());
    web.getSettings().setJavaScriptEnabled(true);
    web.loadUrl("http://www.voxelservers.net");
    imageView = (ImageView) findViewById(R.id.imageView);
}

public class myWebClient extends WebViewClient
{
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        // TODO Auto-generated method stub
        super.onPageStarted(view, url, favicon);
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        // TODO Auto-generated method stub

        view.loadUrl(url);
        return true;

    }

    @Override
    public void onPageFinished(WebView view, String url) {
        // TODO Auto-generated method stub
        super.onPageFinished(view, url);

        imageView.setVisibility(View.GONE);
    }
}

// To handle "Back" key press event for WebView to go back to previous screen.
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    if ((keyCode == KeyEvent.KEYCODE_BACK) && web.canGoBack()) {
        web.goBack();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

}

Its just a black screen.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

One way we can achieve this is by rather than opening a new activity for webview, In WelcomeActivity.java itself add webView and imageView to the layout and make webview to invisible or Gone.

On open of WelcomeActivity initialize webView and set custom WebViewClient. Override onPageFinished() in your Custom webViewClient and in this method make webview visible and imageView to Gone.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...