【HarmonyOS NEXT】如何实现页面滑动过程中动态修改状态栏文字颜色

 【关键字】

状态栏 / 字体颜色 / 动态修改

【问题描述】

刚进入页面时状态栏中的时间、电量、wifi等文字的颜色为白色,随着页面向上滚动,状态栏内容颜色需要变为黑色,是否有方法支持状态栏颜色的修改。

【解决方案】

可以使用import window from '@ohos.window'; 中的SystemBarProperties属性修改状态栏的颜色,根据自己业务属性监听对应的滑动时间,然后做出对应的颜色修改。

Demo如下:

import measure from '@ohos.measure'
import window from '@ohos.window';
@Entry
@Component
struct MeasureDemo {
@State message: string = 'Hello World';
private scrollerForList: Scroller = new Scroller()
private arr: number[] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
@State measure: SizeOptions = measure.measureTextSize({
textContent: this.message,
})
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Text('测试文本宽度:' + this.measure.width)
Text('测试文本高度:' + this.measure.height)
Button("onclick").onClick(() => {
window.getLastWindow(getContext(this), (err, win) => {
win.setWindowSystemBarProperties({statusBarContentColor : '#ff00ff'})
})
})
List({ space: 20, scroller: this.scrollerForList }) {
ForEach(this.arr, (item: number) => {
ListItem() {
Text("ListItem" + item)
.width("100%")
.height("100%")
.borderRadius(15)
.fontSize(16)
.textAlign(TextAlign.Center)
.backgroundColor(Color.White)
}.width("100%").height(100)
}, (item: string) => item)
}
.width("100%")
.height("50%")
.edgeEffect(EdgeEffect.None)
.friction(0.6)
.onScroll(() => {
window.getLastWindow(getContext(this), (err, win) => {
win.setWindowSystemBarProperties({statusBarContentColor : '#ff00ff'})
})
})
}
.width('100%')
}
.height('100%')
.backgroundColor(Color.Pink)
}
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值