我需要顯示啓動畫面,直到網頁加載到webview。完成網站加載啓動畫面
我使用下面的代碼。有可能嗎?
public class SplashScreen extends Activity {
protected Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_splash_screen);
intent = new Intent(getApplicationContext(), MainActivity.class);
// MainActivity.class contains WebView
Thread myThread = new Thread() {
@Override
public void run() {
try {
sleep(5000);
startActivity(intent);
finish();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
myThread.start();
}
}
而且
public class MainActivity extends Activity {
private WebView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
String url = "http://google.com";
view = (WebView)this.findViewById(R.id.webView1);
view.clearCache(true);
WebSettings s = view.getSettings();
s.setJavaScriptEnabled(true);
s.setCacheMode(WebSettings.LOAD_DEFAULT);
s.setDomStorageEnabled(true);
view.loadUrl(url);
}