HarmonyOS TimePicker 能否自定义背景色?

请问下TimePicker 能否自定义背景色,效果见图片

阅读 413
1 个回答

TimePicker暂不支持,您可以把TimePicker的背景色设为透明,通过堆叠达到你想要的效果,可以参考

@Entry
@Component
struct TimePickerExample {
  @State isMilitaryTime: boolean = false
  private selectedTime: Date = new Date('2022-07-22T08:00:00')

  build() {
    Column() {
      Button('切换12小时制/24小时制')
        .margin(30)
        .onClick(() => {
          this.isMilitaryTime = !this.isMilitaryTime
        })
      Stack() {
        Column().backgroundColor(Color.Yellow).zIndex(1).width(500).height(500)
        Row()
          .backgroundColor(Color.Orange)
          .zIndex(2)
          .width(300)
          .height(60)
          .offset({ y: 10 })
        TimePicker({
          selected: this.selectedTime,
        })
          .zIndex(3)
          .backgroundColor('#00000000')
          .useMilitaryTime(this.isMilitaryTime)
          .onChange((value: TimePickerResult) => {
            if (value.hour >= 0) {
              this.selectedTime.setHours(value.hour, value.minute)
              console.info('select current date is: ' + JSON.stringify(value))
            }
          })
          .disappearTextStyle({ color: Color.Red, font: { size: 15, weight: FontWeight.Lighter } })
          .textStyle({ color: Color.Black, font: { size: 20, weight: FontWeight.Normal } })
          .selectedTextStyle({ color: Color.Blue, font: { size: 30, weight: FontWeight.Bolder } })
      }
    }.width('100%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进