2

在我的应用程序中,有两个活动。第一个是 Splashscreen,第二个是 Webview 活动。启动画面显示后,我想显示我的 webview 活动。但是在启动画面之后,2-3 秒出现一个空白的白色屏幕,然后加载 webview 活动。关于如何忽略这个白色屏幕的任何想法。我在许多帖子中研究了这个问题的解决方案,但没有成功。任何帮助将不胜感激。

添加代码:闪屏活动:

@Override
protected void onStart() {
    super.onStart();
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            finish();
            startActivity(new Intent(SplashScreen.this,
                    WebViewActivity.class));
        }
    }, DELAY);
}
4

3 回答 3

1

工作代码

public class WebActivity extends Activity {

protected boolean _active = true;

protected int _splashTime = 3000;

Thread splashTread;

private boolean stop = false;

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

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

    splashTread = new Thread() {
        @Override
        public void run() {
            try {
                int waited = 0;
                while(_active && (waited < _splashTime)) {
                    sleep(100);
                    if(_active) {
                        waited += 100;
                    }
                }

            } catch(InterruptedException e) {
                // do nothing
            } finally {

                if(!stop){
                    startActivity(new Intent(WebActivity.this,Home.class));
                    finish();
                }
                else
                    finish();
            }
        }

    };
    splashTread.start();

}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {

        if(splashTread.isAlive())
            this.stop = true;
    }
    return true;
}
}
于 2013-02-06T09:33:48.030 回答
0

创建两个类文件,如 WebActivity.java、home.java。

WebActivity.java

       Handler handler = new Handler();

    // run a thread after 2 seconds to start the home screen
    handler.postDelayed(new Runnable() {

        @Override
        public void run() {

            // make sure we close the splash screen so the user won't come
            // back when it presses back key

            finish();
            // start the home screen

            ProgressDialog pd = new ProgressDialog(WebActivity.this);

            //use this before calling intent
                          pd.setMessage("Processing...");

            pd.show();



            Intent intent = new Intent(WebActivity.this, Home.class);

            WebActivity.this.startActivity(intent);

        }

    }, 2000); // time in milliseconds (1 second = 1000 milliseconds) until the run() method will be called

主页.java

   webview=(WebView)findViewById(R.id.webView1);
webview.setWebViewClient(new myWebClient());

webview.loadUrl("http://www.google.com");}

 public class myWebClient extends WebViewClient

 {

     @Override

        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            // TODO Auto-generated method stub


            view.loadUrl(url);

            return true;

        }
 }

安卓清单

只需添加活动类并设置互联网权限即可加载 webview

于 2013-02-05T09:05:32.197 回答
0

完成启动画面后,网页加载需要一些时间。这就是为什么您会看到出现空白屏幕的原因。一旦 web 视图开始加载进度条。试试这个链接。这将对您有所帮助。 http://www.technotalkative.com/android-load-webview-with-progressbar/

于 2013-02-01T09:44:48.503 回答