解决方法
如果你的意思是预装载图像有Splash屏幕,请参考以下代码;
对于PhoneGap:
public class MyDefaultActivity extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setIntegerProperty("splashscreen",R.drawable.splash); // Displays the splash screen for android super.loadUrl("file:///android_asset/www/index.html",3000); // Second parameter is duration for delay of splash screen } }
对于Android Native应用程序:
public class MySplashScreen extends Activity { private CountDownTimer lTimer; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.splashscreen); // Contains only an LinearLayout with backround as image drawable lTimer = new CountDownTimer(5000,1000) { public void onFinish() { closeScreen(); } @Override public void onTick(long millisUntilFinished) { // TODO Auto-generated method stub } }.start(); } private void closeScreen() { Intent lIntent = new Intent(); lIntent.setClass(this,MyLauncherActivity.class); startActivity(lIntent); finish(); } }
确保一个名为splash.png的文件作为res / drawable-hdpi / splash.png(RGBA)存在.