在我的应用程序中,有两个activities.First是闪屏和第二个是Webview活动。在闪屏显示后,我想在闪屏后显示我的webview activity.But,2-3秒钟一个空白的白屏出现,然后webview活动得到loaded.Any关于如何忽略这个白屏的想法。我在许多帖子中寻找了这个问题的解决方案,但都没有成功。任何帮助都将不胜感激。
添加代码: Splashscreen活动:
@Override
protected void onStart() {
super.onStart();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
finish();
startActivity(new Intent(SplashScreen.this,
WebViewActivity.class));
}
}, DELAY);
}发布于 2013-02-06 17:33:48
工作代码
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-01 17:44:49
完成闪屏后,网页加载需要一些时间。这就是为什么你会看到一个空白的白屏出现。一旦web视图启动,就会加载进度条。请尝试此链接。这对你会有帮助的。http://www.technotalkative.com/android-load-webview-with-progressbar/
发布于 2013-02-05 17:05:32
创建两个类文件,如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 calledHome.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;
}
}安卓清单
只需添加activity类并设置internet权限即可加载webview
https://stackoverflow.com/questions/14643264
复制相似问题