cordova-plugin-splashscreen-启动页

node 10.15.0
ionic 4.12.0
cordova 9.0
# platforms
cordova-android:8.0.0
cordova-ios: 5.0.0

安装

ionic cordova plugin add cordova-plugin-splashscreen
npm install @ionic-native/splash-screen

配置

config.xml

属性配置

// 拉伸
<preference name="SplashMaintainAspectRatio" value="true" />
// 淡入效果
<preference name="FadeSplashScreen" value="true" />
// 淡入延时
<preference name="FadeSplashScreenDuration" value="300" />
// 是否仅首次显示
<preference name="SplashShowOnlyFirstTime" value="false" />
<preference name="SplashScreen" value="screen" />
// 启动页延时
<preference name="SplashScreenDelay" value="20000" />
// 自动隐藏 默认true
<preference name="AutoHideSplashScreen" value="false" />

资源配置

可根据自身情况选择相应的资源

<platform name="android">
        <allow-intent href="market:*" />
        <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="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>
<platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
        <icon height="57" src="resources/ios/icon/icon.png" width="57" />
        <icon height="114" src="resources/ios/icon/icon@2x.png" width="114" />
        <icon height="40" src="resources/ios/icon/icon-40.png" width="40" />
        <icon height="80" src="resources/ios/icon/icon-40@2x.png" width="80" />
        <icon height="120" src="resources/ios/icon/icon-40@3x.png" width="120" />
        <icon height="50" src="resources/ios/icon/icon-50.png" width="50" />
        <icon height="100" src="resources/ios/icon/icon-50@2x.png" width="100" />
        <icon height="60" src="resources/ios/icon/icon-60.png" width="60" />
        <icon height="120" src="resources/ios/icon/icon-60@2x.png" width="120" />
        <icon height="180" src="resources/ios/icon/icon-60@3x.png" width="180" />
        <icon height="72" src="resources/ios/icon/icon-72.png" width="72" />
        <icon height="144" src="resources/ios/icon/icon-72@2x.png" width="144" />
        <icon height="76" src="resources/ios/icon/icon-76.png" width="76" />
        <icon height="152" src="resources/ios/icon/icon-76@2x.png" width="152" />
        <icon height="167" src="resources/ios/icon/icon-83.5@2x.png" width="167" />
        <icon height="29" src="resources/ios/icon/icon-small.png" width="29" />
        <icon height="58" src="resources/ios/icon/icon-small@2x.png" width="58" />
        <icon height="87" src="resources/ios/icon/icon-small@3x.png" width="87" />
        <icon height="1024" src="resources/ios/icon/icon-1024.png" width="1024" />
        <splash height="1136" src="resources/ios/splash/Default-568h@2x~iphone.png" width="640" />
        <splash height="1334" src="resources/ios/splash/Default-667h.png" width="750" />
        <splash height="2208" src="resources/ios/splash/Default-736h.png" width="1242" />
        <splash height="1242" src="resources/ios/splash/Default-Landscape-736h.png" width="2208" />
        <splash height="1536" src="resources/ios/splash/Default-Landscape@2x~ipad.png" width="2048" />
        <splash height="2048" src="resources/ios/splash/Default-Landscape@~ipadpro.png" width="2732" />
        <splash height="768" src="resources/ios/splash/Default-Landscape~ipad.png" width="1024" />
        <splash height="2048" src="resources/ios/splash/Default-Portrait@2x~ipad.png" width="1536" />
        <splash height="2732" src="resources/ios/splash/Default-Portrait@~ipadpro.png" width="2048" />
        <splash height="1024" src="resources/ios/splash/Default-Portrait~ipad.png" width="768" />
        <splash height="960" src="resources/ios/splash/Default@2x~iphone.png" width="640" />
        <splash height="480" src="resources/ios/splash/Default~iphone.png" width="320" />
        <splash height="2732" src="resources/ios/splash/Default@2x~universal~anyany.png" width="2732" />
</platform>

使用

app.module.ts

import {SplashScreen} from '@ionic-native/splash-screen/ngx';
providers: [
  SplashScreen,
]

app.conponent.ts

import {SplashScreen} from '@ionic-native/splash-screen/ngx';
initializeApp() {
    this.platform.ready().then(() => {
      this.initSplashScreen();
    });
  }
// 淡入效果
initSplashScreen() {
    setTimeout(() => {
      this.splashScreen.hide();
    }, 300);
}

注意事项:

  1. 必须在AppModule中声明。

下一篇将介绍状态栏插件:cordova-plugin-statusbar

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Plugin.xml plugin.xml文件定义了你的插件所需的结构和设置。它有几个元素来提供有关你的插件的详细...
    葛高召阅读 1,298评论 0 1
  • cordova基于HTML、CSS和JavaScript的,用于创建跨平台移动应用程序的快速开发平台。能够利用iP...
    sunsboyxu阅读 2,748评论 0 6
  • 导语 Apache Cordova是一个开源的移动开发框架。允许你用标准的web技术-HTML5,CSS3和Jav...
    ApolloGuibo阅读 4,561评论 2 9
  • 衔着窗外轰轰烈烈大雨声转醒的喜,一盆一盆的花草也全搬去了窗台淋雨——啊啊误会,猫你怕水不要跟去,一起听雨很好——人...
    郁致阅读 305评论 0 1
  • 看完《釜山行》之后,有成功燃起了自己对韩国电影的向往,于是上网搜到了《隧道》这部电影。 隧道主要讲述了男主在回...
    yyszl阅读 17,027评论 0 0

友情链接更多精彩内容