【问题标题】:After splashscreen, a white blank screen comes and then webview is loaded在启动画面之后,出现一个白色的空白屏幕,然后加载 webview
【发布时间】:2015-06-03 13:22:45
【问题描述】:

在我的应用程序中,有两个活动。第一个是 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);
}

【问题讨论】:

  • 您可能在代码中犯了错误。
  • 也许你已经分开了,签入manifast文件,
  • @TomerMor 你能详细说明一下评论吗?
  • Webview 似乎需要一些时间才能加载。那么,如何使用 onPreexecute 方法中的 progressDialog 在 AsynTask 中加载 webview?
  • 问题不清楚...加载屏幕时是否要避免白屏或显示任何其他背景颜色?

标签: android android-webview splash-screen


【解决方案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;
}
}

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 请在完全加载webview后修复`进度条然后看不到进度条`。看不懂。
    • @Peter 这个解决方案还会显示 2-3 秒的空白屏幕。
    • @peter :我猜这是 android 中的默认行为。它仍然显示空白屏幕。
    • @androiduser,默认 webview 背景颜色为白色。如果您想避免出现白色空白屏幕,请为该 webview 设置透明颜色。
    【解决方案3】:

    创建两个类文件,如 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
    

    Home.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;
    
            }
     }
    

    Android 清单

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

    【讨论】:

    • 这正是我所做的......但是在启动画面完成后和 webview 加载之前,一个白色的空白屏幕会出现 2-3 秒......
    猜你喜欢
    • 2017-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-18
    • 2018-03-18
    • 2015-06-21
    • 2023-02-10
    • 1970-01-01
    相关资源
    最近更新 更多