1# 启动页实现案例 2 3### 介绍 4 5本示例介绍了使用资源匹配规则实现不同分辨率冷启动应用图标适配和启动广告页的实现。 应用使用某资源时,系统会根据当前设备状态优先从相匹配的限定词目录中寻找该资源。只有当resources目录中没有与设备状态匹配的限定词目录,或者在限定词目录中找不到该资源时,才会去base目录中查找。rawfile是原始文件目录,不会根据设备状态去匹配不同的资源。 6 7### 效果预览 8 9<img src='screenshots/devices/window_start_icon.jpeg' width="270"> 10 11### 使用说明 12 131. 应用安装到不同分辨率的设备冷启动,显示不同大小的图标 142. 点击应用冷启动弹出加载出广告页面 15 16### 实现思路 171. 新建图片资源 182. 修改module.json5配置文件 193. 新增页面作为启动页面 20 21### 实现步骤 221. 在resources目录右键菜单选择“New > Image Asset”,选择设备和图标类型后可创建限定词目录,按照命名规范自动生成限定词和资源组目录,并将文件创建在限定词目录中。 23  24 252. 将对应不同分辨率需要显示的图标放到对应文件夹中(图标名称需保持一致),不同文件夹对应屏幕密度如下表 26 | 名称 | 值 | 说明 | 27 | -------------- | ---- | ---------- | 28 | SCREEN_SDPI | 120 | 小规模的屏幕密度。 | 29 | SCREEN_MDPI | 160 | 中规模的屏幕密度。 | 30 | SCREEN_LDPI | 240 | 大规模的屏幕密度。 | 31 | SCREEN_XLDPI | 320 | 特大规模的屏幕密度。 | 32 | SCREEN_XXLDPI | 480 | 超大规模的屏幕密度。 | 33 | SCREEN_XXXLDPI | 640 | 超特大规模的屏幕密度。 | 343. 修改module.json5中abilities的icon和startWindowIcon字段为第二步中的图标名称 35```ts 36"abilities": [ 37 { 38 "name": "EntryAbility", 39 "srcEntry": "./ets/entryability/EntryAbility.ets", 40 "description": "$string:EntryAbility_desc", 41 "icon": "$media:icon", 42 "label": "$string:EntryAbility_label", 43 "startWindowIcon": "$media:start_window_icon", 44 "startWindowBackground": "$color:entry_start_window_background", 45 "exported": true, 46 "skills": [ 47 { 48 "entities": [ 49 "entity.system.home" 50 ], 51 "actions": [ 52 "action.system.home" 53 ] 54 } 55 ] 56 } 57 ], 58 ``` 594. 新增一个页面作为启动页面,通过定时器设定固定时间跳转到主页也可手动跳过,该页面可以作为应用广告页面,可将部分ability实例生命周期中的加载逻辑和数据获取逻辑移到广告页面中加载减少ability实例创建时长。 60```ts 61// 页面显示时打开定时器 62onPageShow() { 63 this.changeFullScreen(true) 64 this.timer = setInterval(() => { 65 this.pageCountDown--; 66 if (this.pageCountDown === 0) { 67 this.changeFullScreen(false); 68 clearInterval(this.timer); // 关闭定时器 69 router.replaceUrl({ url: 'pages/EntryView' }); 70 } 71 }, 1000) 72} 73 ``` 74### 高性能知识点 75 76**不涉及** 77 78### 工程结构&模块类型 79 80``` 81WindowStartIcon 82|---entryability 83| |---EntryAbility.ets // EntryAbility 84|---entryformability 85| |---EntryFormAbility.ets // EntryBackupAbility 86|---pages 87| |---AdvertisingPage.ets // 开屏广告页面 88| |---Index.ets // 首页页面 89|---resources // 资源文件管理 90| |---base // 默认资源 91| |---en_US // 英文资源 92| |---zh_CN // 中文资源 93| |---sdpi // 小屏dpi图标 94| |---mdpi // 中屏dpi图标 95| |---ldpi // 大屏dpi图标 96| |---xldpi // 特大屏dpi图标 97| |---xxldpi // 超大屏dpi图标 98| |---xxxldpi // 超特大屏dpi图标 99``` 100 101### 参考资料 102 103[资源分类与访问](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/quick-start/resource-categories-and-access.md) 104 105### 依赖 106不涉及 107 108### 约束与限制 1091.本示例仅支持标准系统上运行,支持设备:RK3568。 110 1112.本示例已适配API version 12(5.0.0.70)版本SDK。 112 1133.本示例需要使用DevEco Studio NEXT Release(Build Version: 5.0.3.900)及以上版本才可编译运行。 114 115### 下载 116如需单独下载本工程,执行如下命令: 117 118``` 119git init 120git config core.sparsecheckout true 121echo code/UI/WindowStartIcon/ > .git/info/sparse-checkout 122git remote add origin https://gitee.com/openharmony/applications_app_samples.git 123git pull origin master 124```