Phonegap - 为 Android 应用添加启动画面 [英] Phonegap - add a splash screen for Android app

查看:35
本文介绍了Phonegap - 为 Android 应用添加启动画面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我如何向我的基于 HTML5 Phonegap 的 Android 应用程序添加启动画面.我只希望它在加载时显示 5 秒.另外 - 任何人都可以建议启动画面应该是什么尺寸.

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.

推荐答案

为了在 PhoneGap Android 应用程序中出现启动画面,您需要将 splash.png 文件放入 res/drawable-ldpires/drawable-mdpires/drawable-hdpires/drawable-xhdpi.这些目录代表每英寸低、中、高和超大点数.您需要为每个目录调整 splash.png 的大小(此处文件名很重要),否则 Android 会为您拉伸.

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):至少 960 x 720
  • 大 (hdpi):至少 640 x 480
  • 中 (mdpi):至少 470 x 320
  • 小 (ldpi):至少 426 x 320

然后在扩展 DroidGap 的主 Java 类中,您需要添加一行并修改另一行.首先添加:

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);

这一行应该出现在 super.onCreate 下,但在 super.loadUrl 之前.然后,您需要修改 loadUrl 方法以在加载主页之前暂停 5 秒钟.它看起来像这样:

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);

这应该对你有用.

我最近对 ​​SplashScreen 在 PhoneGap Android 上的工作方式进行了一些更新.主应用程序现在在显示启动画面时加载.与之前的阻塞启动画面调用相比,这是一个很大的改进.在我的博客上阅读有关更改的更多信息.

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.

这篇关于Phonegap - 为 Android 应用添加启动画面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆