Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonegap - add a splash screen for Android app

Could anybody please advise how I can add a splash screen to my HTML5 Phonegap based Android App. I just want it to display for 5 seconds on load. Also - can anybody advise what dimensions the splash screen should be.

like image 299
Dancer Avatar asked Nov 16 '11 18:11

Dancer


People also ask

How do I add a splash screen to an existing project?

To do this, first create an XML drawable in res/drawable. It just a layerlist with logo in center background color with it. This theme will have no actionbar and with background that we just created above. And in manifest you need to set SplashTheme to activity that you want to use as splash.

Does Android have a splash screen?

Starting in Android 12, the launch animation for all apps when running on a device with Android 12 or higher. This includes an into-app motion at launch, a splash screen showing your app icon, and a transition to your app itself.


2 Answers

In order to have a splash screen in a PhoneGap Android application you need to put your splash.png file into res/drawable-ldpi, res/drawable-mdpi, res/drawable-hdpi, res/drawable-xhdpi. Where those directories represent low, medium, high and extra large dots per inch. You'll need to resize you splash.png (the file name is important here) for each directory or Android will stretch it for you.

The sizes of each image should be:

  • xlarge (xhdpi): at least 960 x 720
  • large (hdpi): at least 640 x 480
  • medium (mdpi): at least 470 x 320
  • small (ldpi): at least 426 x 320

Then in your main Java class, the one that extends DroidGap, you'll need to add one line and modify another. First add:

super.setIntegerProperty("splashscreen", R.drawable.splash); 

this line should show up under super.onCreate but before super.loadUrl. Then you'll need to modify your loadUrl method to pause for 5 seconds before loading up the main page. It would look like this:

super.loadUrl("file:///android_asset/www/index.html", 5000); 

That should do it for you.

I've recently made some updates to how the SplashScreen works on PhoneGap Android. The main app now loads while the splash screen is being shown. This is a big improvement over the previous blocking splash screen call. Read more about the changes on my blog.

like image 179
Simon MacDonald Avatar answered Oct 13 '22 04:10

Simon MacDonald


Phonegap (Apache Cordova) documentation has enough details about the splash screen and different resolutions for both Android and iOS at one place.

http://docs.phonegap.com/en/2.2.0/cordova_splashscreen_splashscreen.md.html

like image 40
Rajiv Avatar answered Oct 13 '22 04:10

Rajiv