全局UI方法-弹窗五-时间滑动选择器弹窗(TimePickerDialog)

news/2024/7/21 9:56:34 标签: openHarmony, harmonyos, 华为

1、描述

        以24小时的时间区间创建时间滑动选择器,展示在弹窗上。

2、接口

        TimePickerDialog.show(options?: TimePickerDialogOptions)

3、TimePickerDialogOptions

参数名

参数类型

必填

参数描述

selected

Date

设置当前选中的时间。

默认值:当前系统时间

userMilitaryTmeboolean展示时间是否为24小时制,默认为12小时制。默认值:false。
onAccept(value:TimePickerResult) => void点击弹窗中的“确定”按钮时触发该回调。
onCancel() => void点击弹窗中的“取消”按钮时触发该回调。
onChange(value:TimePickerResult) => void滑动弹窗中的选择器使当前选中时间改变时触发该回调。

4、TimePickerResult对象说明

返回值为24小时制时间。

名称

参数类型

描述

hour

number

选中时间的时。

取值范围:[0-23]

minute

number

选中时间的分。

取值范围:[0-59]

5、示例

@Entry
@Component
struct TimePickerDialogPage {
  @State message: string = '定义时间滑动选择器弹窗'

  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(20)
          .fontWeight(FontWeight.Bold)
          .width("96%")
          .margin({ top: 12 })

        Button("TimePickerDialog 12 Hour")
          .width("96%")
          .fontSize(20)
          .margin({ top: 12 })
          .onClick(() => {
            TimePickerDialog.show({
              onAccept: (result: TimePickerResult) => {
                console.info("TimePickerDialog Default onAccept result = " + JSON.stringify(result));
              },
              onCancel: () => {
                console.info("TimePickerDialog Default onCancel");
              },
              onChange: (result: TimePickerResult) => {
                console.info("TimePickerDialog Default onChange result = " + JSON.stringify(result));
              }
            })
          })

        Button("TimePickerDialog 24 Hour")
          .width("96%")
          .fontSize(20)
          .margin({ top: 12 })
          .onClick(() => {
            TimePickerDialog.show({
              selected: new Date("2024-01-20T20:30:00"),
              useMilitaryTime: true,
              onAccept: (result: TimePickerResult) => {
                console.info("TimePickerDialog Default onAccept result = " + JSON.stringify(result));
              },
              onCancel: () => {
                console.info("TimePickerDialog Default onCancel");
              },
              onChange: (result: TimePickerResult) => {
                console.info("TimePickerDialog Default onChange result = " + JSON.stringify(result));
              }
            })
          })

      }
      .width('100%')
      .height("100%")
    }
    .height('100%')
  }
}

6、效果图


http://www.niftyadmin.cn/n/5456806.html

相关文章

显示器接口的了解

显示器视频接口科普:看完就懂HDMI、DP、DVI、VGA、USB-C哪个更适合你的电脑外接显示器_哔哩哔哩_bilibili 电脑显示接口: VGA,DVI,HDMI,DP,USB-C VGA:基本被淘汰了。 常见的还是HDMI1.4和2.0规格 更适合电脑使用的DP接口(免费)…

速盾:cdn流畅的播放服务有哪些

CDN(Content Delivery Network)是一种分布式网络架构,用于加速互联网内容的传输,提供快速、可靠的内容传递服务。CDN流畅的播放服务在互联网视频行业中至关重要,它可以确保视频内容在不同地区和网络环境下都能够流畅播…

【如何在Python中替换文件路径和要读取的行号】

在Python中,替换文件路径和要读取的行号是非常简单的,因为这些通常只是传递给函数或脚本的字符串变量。下面是如何做到这一点的例子: 首先,假设你有一个函数,它接受文件路径和行号作为参数,并读取那一行。…

010——服务器开发环境搭建及开发方法(下)

目录 三、 第一个驱动程序 四、 buildroot 4.1 制作根文件系统 4.2 buildroot使用 五、 uboot 009——服务器开发环境搭建及开发方法(上)-CSDN博客 三、 第一个驱动程序 # 1. 使用不同的开发板内核时, 一定要修改KERN_DIR # 2. KERN_DIR中的内核要…

实验02-1 C#和ASP.NET控件:在Web窗体中输出九九乘法表

【实验内容及要求】 1. 在Web窗体中输出九九乘法表 浏览效果如图2-1所示。 图2-1 在Default.aspx.cs中编写C#代码 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;public par…

<QT基础(5)>事件监听

事件监听 事件监听(Event Handling)是在程序中监视和响应发生的事件的一种机制。在Qt中,事件监听是一种常见的用于处理用户输入、系统事件以及其他类型事件的方法。通过事件监听,您可以在发生特定事件时捕获事件并执行相应的操作…

【前端面试3+1】04浏览器存储、flex布局属性和常用指令、 promise和async await区别

一、浏览器存储 1.1类型: 浏览器数据存储的方式有以下几种: Cookie:小型文本文件,存储在用户计算机上,可以通过浏览器传输到服务器。Web Storage:包括LocalStorage和SessionStorage,可以在浏览器…

Flutter 中的 ScrollNotification 为啥收不到

1. 需求 在做智家 APP 悬浮窗优化需求时&#xff0c;需要获取列表的滑动并通知悬浮窗进行收起或全部显示。 基础库同事已经把 基础逻辑整理好如下&#xff1a; NotificationListener<ScrollNotification>(onNotification: (notification){//1.监听事件的类型if (notif…