Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...