【问题标题】:How can i use a splashscreen plugin in a phonegap app?如何在 phonegap 应用程序中使用闪屏插件?
【发布时间】:2015-09-22 12:02:36
【问题描述】:

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

【问题讨论】:

    标签: android cordova plugins


    【解决方案1】:

    使用这个。

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

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

    【讨论】:

      【解决方案2】:

      这是我的 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>

      【讨论】:

        【解决方案3】:

        您需要为每个平台生成资源并将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 后,您可以在根目录(您的 config.xml 文件所在的位置)创建一个文件夹 resources 并将您的资源放在那里。 如果您只想构建启动画面,只需在其中复制一个splash.png 文件。更多信息here

        当您完成该运行时:

        ionic resources
        

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

        cordova 闪屏插件现已移至 npm 注册表中,因此如果您想使用最新的:

        cordova plugin add cordova-plugin-splashscreen
        

        现在您可以使用

        添加启动画面

        在您的配置文件中。

        更多信息here

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-10-23
          • 1970-01-01
          • 1970-01-01
          • 2017-07-31
          • 2014-01-08
          • 1970-01-01
          相关资源
          最近更新 更多