鸿蒙做一个广告页
·
import { window } from '@kit.ArkUI'
@Entry
@Component
struct GuanggaoDemo {
@State
isShow: boolean = false
@State
isTimeStart: boolean = false
@State
timeShow: number = 5
timer: number = 0
aboutToAppear(): void {
window.getLastWindow(getContext()).then((win) => {
win.setWindowLayoutFullScreen(true)
})
this.setTime()
}
setTime() {
this.isShow = true
this.isTimeStart = true
this.timeShow = 5
if (this.isTimeStart) {
this.timer = setInterval(() => {
if (this.timeShow <= 0) {
clearInterval(this.timer)
this.isShow = false
return
} else {
this.timeShow--
}
}, 1000)
} else {
this.timeShow = 5
}
}
@Builder
Guanggao() {
Column() {
Row() {
Text(this.timeShow + "")
.width(60)
.borderRadius(30)
.backgroundColor(Color.Blue)
.fontColor(Color.White)
.textAlign(TextAlign.Center)
.onClick(() => {
this.isShow = false
clearInterval(this.timer)
})
}.width('100%').justifyContent(FlexAlign.End)
.padding({
top: 50,
right: 40
})
}.width('100%').height('100%').backgroundColor(Color.Pink)
}
build() {
Column() {
Button("显示广告")
.onClick(() => {
this.setTime()
})
}
.height('100%')
.width('100%')
.justifyContent(FlexAlign.Center)
.bindContentCover($$this.isShow, this.Guanggao(), {
modalTransition: ModalTransition.ALPHA
})
}
}

更多推荐


所有评论(0)