
回复
【本文正在参加 2023「盲盒」+码有奖征文活动】 https://ost.51cto.com/posts/25284
@toc
本文提到的内容适用于 OpenHarmony 3.2,通过修改系统启动器源码实现动态壁纸的初步方案。其实在 OpenHarmony 4.0 Beta2 中,官方接口也提供了新的修改壁纸的接口,包括动态壁纸设置。
系统桌面仓库:https://gitee.com/openharmony/applications_launcher/tree/OpenHarmony-3.2-Release/
product/phone/src/main/ets/pages
下新增一个 DynamicWallpaper.ets
(除了放置Video组件外,我也尝试过Web组件用于加载网页作为壁纸,但是实际测试中Web组件无法正常加载,原因未知)import webview from '@ohos.web.webview'
@Component
export default struct DynamicWallpaper {
webviewController: webview.WebviewController = new webview.WebviewController()
videoController: VideoController = new VideoController()
onPageShow() {
this.videoController.start()
}
onPageHide() {
// this.videoController.pause()
}
build() {
Column() {
/*Web({ src: $rawfile("index.html"), controller: this.webviewController })
.zoomAccess(false)
.mediaPlayGestureAccess(false)
.horizontalScrollBarAccess(false)
.verticalScrollBarAccess(false)
.fileAccess(true)
.domStorageAccess(true)
.databaseAccess(true)
.javaScriptAccess(true)
.width('100%')
.height('100%')*/
Video({
src: $rawfile('video1.mp4'),
currentProgressRate: PlaybackSpeed.Speed_Forward_1_00_X,
controller: this.videoController
})
.width('100%')
.height('100%')
.loop(true)
.autoPlay(true)
.controls(false)
}
.width('100%')
.height('100%')
}
}
product/phone/src/main/resources/rawfile
下面新增 video1.mp4
product/phone/src/main/ets/pages/EntryView.ets
,在 Stack()
布局中加入 DynamicWallpaper()
(Stack层叠布局中,元素可以重叠的布局,后一个子元素覆盖前一个子元素,子元素可以叠加,也可以设置位置)import DynamicWallpaper from './DynamicWallpaper';
......
build() {
Stack() {
DynamicWallpaper()
......
}
.backgroundImage(StyleConstants.DEFAULT_BACKGROUND_IMAGE)
.backgroundImageSize(ImageSize.Cover)
.backgroundImagePosition(Alignment.Center)
.width('100%')
.height('100%')
}
本文主要是修改系统启动器源码的一些经验分享,有关系统应用签名构建,推荐阅读TiZizzz写的这篇文章:https://ost.51cto.com/posts/21466 ,可以说是写的非常详细了。