import { UIAbility } from '@kit.AbilityKit';
import { window } from '@kit.ArkUI';
export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage: window.WindowStage): void {
windowStage.loadContent('pages/SplashPage', (err) => {
if (err.code) {
// 异常处理
return;
}
// 获取主窗口
windowStage.getMainWindow((err, data) => {
// 切换窗口方向为横屏
data.setPreferredOrientation(window.Orientation.AUTO_ROTATION_LANDSCAPE_RESTRICTED);
});
});
}
} 效果如下:

{
"module": {
"name": "entry",
"type": "entry",
"description": "$string:module_desc",
"mainElement": "EntryAbility",
"deviceTypes": [
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"abilities": [
{
"name": "EntryAbility",
"srcEntry": "./ets/entryability/EntryAbility.ets",
"description": "$string:EntryAbility_desc",
"icon": "$media:layered_image",
"label": "$string:EntryAbility_label",
"startWindowIcon": "$media:startIcon",
"startWindowBackground": "$color:start_window_background",
"exported": true,
// 配置当前UIAbility组件启动时的方向为(反向)横向
"orientation": "auto_rotation_landscape_restricted",
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"ohos.want.action.home"
]
}
]
}
],
}
} 效果如下:

@Entry
@Component
struct SplashPage {
build() {
Column() {
Image($r('app.media.back_font'))
// 配置图片保持宽高比适当缩放,水平居中,填充视图
.objectFit(ImageFit.Auto)
}
.height('100%')
.width('100%')
}
} 效果如下:
