如何在phonegap应用中使用splashscreen插件?

时间:2015-09-22 12:02:36

标签: android cordova plugins

我正在开发一个使用phonegap的Android应用程序,但我在展示启动画面时遇到了挑战,我已阅读了许多文档(phonegap文档)和许多论坛,但我没有找到解决方案。我可以采取哪些步骤来解决这个问题? 我试过的插件是" org.apache.cordova.splashscreen "

3 个答案:

答案 0 :(得分:0)

使用此功能。

<preference name="auto-hide-splash-screen"    value="true" />    
<gap:splash src="splash.png" /> // splash.png will be your splash image

如果您仍有任何问题,请分享您的config.xml

答案 1 :(得分:0)

这是我的config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0" id="com.myapplication.app" versionCode="10" version="1.0.0">

  <name>My App</name>
  <description>
   My App
  </description>
  <author href="https://myapp.co.uk/developer" email="jasperltd@gmail.com">
    Jasper Tech
  </author>
  <access origin=".*" />
  <gap:plugin name="org.apache.cordova.splashscreen" version="0.2.7" />
  <preference name="auto-hide-splash-screen" value="true" />
  <gap:splash src="screen.png" />

  <content src="index.html" />
  <icon src="res/icon/icon.png" platform="android" width="124" height="124" density="mdpi" />
  <preference name="android-minSdkVersion" value="5" />
  <preference name="permissions" value="none" />
  <preference name="target-device" value="universal" />
  <preference name="fullscreen" value="false" />
  <icon src="icon.png" />

  <application android:debuggable="false" />
  <preference name="show-splash-screen-spinner" value="true" />
  <allow-intent href="sms:*" />
  <feature name="http://api.phonegap.com/1.0/device" />
  <preference name="orientation" value="portrait" />
  <feature name="App">
    <param name="android-package" value="org.apache.cordova.App" />
  </feature>
</widget>

答案 2 :(得分:0)

您需要为每个平台生成资源,并将platform部分添加到config.xml文件中:

<platform name="android">
    <icon density="ldpi" src="resources\android\icon\drawable-ldpi-icon.png" />
    <icon density="mdpi" src="resources\android\icon\drawable-mdpi-icon.png" />
    <icon density="hdpi" src="resources\android\icon\drawable-hdpi-icon.png" />
    <icon density="xhdpi" src="resources\android\icon\drawable-xhdpi-icon.png" />
    <icon density="xxhdpi" src="resources\android\icon\drawable-xxhdpi-icon.png" />
    <icon density="xxxhdpi" src="resources\android\icon\drawable-xxxhdpi-icon.png" />
    <splash density="land-ldpi" src="resources\android\splash\drawable-land-ldpi-screen.png" />
    <splash density="land-mdpi" src="resources\android\splash\drawable-land-mdpi-screen.png" />
    <splash density="land-hdpi" src="resources\android\splash\drawable-land-hdpi-screen.png" />
    <splash density="land-xhdpi" src="resources\android\splash\drawable-land-xhdpi-screen.png" />
    <splash density="land-xxhdpi" src="resources\android\splash\drawable-land-xxhdpi-screen.png" />
    <splash density="land-xxxhdpi" src="resources\android\splash\drawable-land-xxxhdpi-screen.png" />
    <splash density="port-ldpi" src="resources\android\splash\drawable-port-ldpi-screen.png" />
    <splash density="port-mdpi" src="resources\android\splash\drawable-port-mdpi-screen.png" />
    <splash density="port-hdpi" src="resources\android\splash\drawable-port-hdpi-screen.png" />
    <splash density="port-xhdpi" src="resources\android\splash\drawable-port-xhdpi-screen.png" />
    <splash density="port-xxhdpi" src="resources\android\splash\drawable-port-xxhdpi-screen.png" />
    <splash density="port-xxxhdpi" src="resources\android\splash\drawable-port-xxxhdpi-screen.png" />
</platform>

我认为,最好的方法是使用Ionic CLI命令,但必须先安装它:

npm install -g ionic

安装CLI后,您可以在根目录中创建文件夹resources(您的config.xml文件所在的位置),并将您的资源放在那里。 如果您只想构建启动画面,只需在其中复制splash.png文件即可。更多信息here

当你完成那次跑步时:

ionic resources

它将为您配置的每个平台构建所需的资源,并为您配置 config.xml 文件。

cordova s​​plashscreen插件现已在npm注册表中移动,所以如果你想使用最新的插件:

cordova plugin add cordova-plugin-splashscreen

现在您可以使用

添加启动画面了

在配置文件中。

更多信息here