1 个回答

你好,目前仅支持置灰配置,请参考:目前可以通过grayscale为组件属性,可以为组件添加灰度效果,实现页面一键置灰效果

关键代码为

.grayscale(this.saturateValue) // 设置根组件的颜色饱和度  

以下为简易demo请参考

@Entry
@Component
struct TabsExample {
  @State selectedFontColor: string = '#007DFF'
  @State saturateValue: number = 0;
  build() {
    Column() {
      Row(){
        Column().width(100).height(100).backgroundColor(Color.Pink)
        Column().width(100).height(100).backgroundColor(Color.Orange)
      }
      Button("页面置灰")
        .onClick(() => {
          this.saturateValue = 1; // 页面置灰
        })

      Button("恢复彩色")
        .onClick(() => {
          this.saturateValue = 0; // 页面复原
        })
    }.width('100%')
    .grayscale(this.saturateValue) // 设置根组件的颜色饱和度
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进