应用启动时动效异常,启动图片未铺满屏幕,周边有空白。

- {
- "abilities": [{
- "name": "EntryAbility",
- "srcEntry": "./ets/entryability/EntryAbility.ets",
- "launchType":"singleton",
- "description": "$string:description_main_ability",
- "icon": "$media:layered_image",
- "label": "Login",
- "startWindow": "$profile:start_window",
- "startWindowIcon": "$media:startWindow",
- "startWindowBackground": "$color:red",
- "process": ":processTag"
- }]
- }


启动页图片的大小与设备分辨率不一致,导致应用启动动画周边有空白。
- @Entry
- @Component
- struct Index {
- pageInfos: NavPathStack = new NavPathStack();
-
- aboutToAppear(): void {
- this.pageInfos.pushPath({ name: 'Splash' }); // 跳转到启动页
- }
-
- build() {
- Navigation(this.pageInfos) {
- Stack() {
- Text('Hello World')
- .fontSize(20)
- .fontWeight(FontWeight.Bold);
- }
- .height('100%')
- .width('100%');
- }
- .hideTitleBar(true)
- .height('100%')
- .width('100%')
- .mode(NavigationMode.Stack);
- }
- }
src/main/ets/pages/Splash.ets:
- import { window } from '@kit.ArkUI';
- import { common } from '@kit.AbilityKit';
-
- @Builder
- export function SplashBuilder() {
- Splash();
- }
-
- @Entry
- @Component
- export struct Splash {
- pageInfos: NavPathStack = new NavPathStack();
-
- setFull(isFull: boolean) {
- let context: common.UIAbilityContext = this.getUIContext().getHostContext() as common.UIAbilityContext;
- window.getLastWindow(context).then((windowClass) => {
- windowClass.setWindowLayoutFullScreen(isFull); // 启动页全屏显示
- let systemBarPropertiesFull: window.SystemBarProperties = {
- statusBarColor: '#00000000',
- statusBarContentColor: '#ffffff'
- };
- let systemBarPropertiesOut: window.SystemBarProperties = {
- statusBarColor: '#ffffff',
- statusBarContentColor: '#000000'
- };
- windowClass.setWindowSystemBarProperties(isFull ? systemBarPropertiesFull : systemBarPropertiesOut);
- });
- }
-
- build() {
- NavDestination() {
- Stack() {
- Image($r('app.media.startWindow')) // $r('app.media.startIcon')需要替换为开发者需要的图片资源文件
- .width('100%')
- .height('100%')
- .syncLoad(true); // 设置图片为同步加载
-
- Column()
- .width('100%')
- .height('123px')
- .linearGradient({
- angle: 0,
- colors: [[0x11000000, 0.0], [0x00000000, 1.0]]
- })
- .position({ y: 0 });
- }
- .height('100%')
- .width('100%');
- }
- .onBackPressed(() => {
- this.pageInfos.pop(); // 弹出路由栈栈顶元素
- return true;
- })
- .onDisAppear(() => {
- this.setFull(false);
- })
- .onReady((navContext: NavDestinationContext) => {
- this.pageInfos = navContext.pathStack;
- this.setFull(true);
- setTimeout(() => {
- this.pageInfos.pop();
- }, 2000);
- })
- .hideTitleBar(true)
- .systemTransition(NavigationSystemTransitionType.NONE)
- .height('100%')
- .width('100%')
- .backgroundColor(Color.White);
- }
- }
src/main/resources/base/profile/router_map.json:
- {
- "routerMap": [
- {
- "name": "Splash",
- "pageSourceFile": "src/main/ets/pages/Splash.ets",
- "buildFunction": "SplashBuilder"
- }
- ]
- }
-
src/main/module.json5文件中需添加"routerMap": "$profile:router_map"。
效果图如下:

合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
解决方案
精准高效的一站式服务支持,助力开发者商业成功