我需要显示启动画面,直到网页在 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);
}