页面滑动过程中动态修改状态栏文字颜色

状态栏文字图标颜色是否支持动态修改。

HarmonyOS
2024-09-23 12:07:54
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zxjiu

可以使用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)  
  }  
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
分享
微博
QQ
微信
回复
2024-09-23 17:14:13


相关问题
HarmonyOS 动态设置状态栏颜色
957浏览 • 1回复 待解决
鸿蒙怎么 修改状态栏字体颜色
13530浏览 • 1回复 待解决
HarmonyOS 状态栏颜色如何修改
1439浏览 • 1回复 待解决
HarmonyOS 修改状态栏颜色不生效
1112浏览 • 1回复 待解决