如何将应用程序预加载器/启动屏幕/启动画面添加到My PhoneGap Android App

use*_*751 8 android cordova

我已经使用手机Gap创建了一个Android应用程序.它运行正常.我如何将预加载器图像添加到我的应用程序.现在它在加载应用程序时显示一个白页.

非常感谢帮助,感谢VKS.

Vin*_*tti 18

如果您的意思是预加载器图像有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
    }
}
Run Code Online (Sandbox Code Playgroud)

对于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();
    }
}
Run Code Online (Sandbox Code Playgroud)

确保调用的文件splash.png存在res/drawable-hdpi/splash.png(RGBA).