1、HarmonyOS 如何自界说时间选择器?
可以参考如下demo:
- let anmDuration: number = 200;
- @Entry
- @Component
- struct TextPickerExample1 {
- @State firstDate: string = '2024-06-19'
- @State date: string = '2024年06月19号'
- controller: CustomDialogController = new CustomDialogController({
- builder: TextPicker1({
- cancel: (date: string) => {
- this.onCancel(date)
- },
- confirm: (date: string, date1: Date) => {
- this.onAccept(date, date1)
- },
- date: this.firstDate,
- }),
- autoCancel:false,
- cornerRadius: 0,
- customStyle: true,
- alignment: DialogAlignment.BottomEnd
- })
- onCancel(date: string) {
- }
- onAccept(date: string, date1: Date) {
- let year: string = date1.getFullYear().toString();
- let month: string = (date1.getMonth() + 1) < 10 ? ('0' + (date1.getMonth() + 1)).toString() : (date1.getMonth() + 1).toString();
- let day: string = date1.getDate().toString();
- this.date = year + '年' + month + '月' + day + '日'
- this.firstDate = year + '-' + month + '-' + day + '-'
- }
- build() {
- Column() {
- Text(this.date)
- Text('日期').onClick(() => {
- this.controller.open()
- })
- }
- }
- }
- @CustomDialog
- struct TextPicker1 {
- aboutToAppear(): void {
- this.selectedDate = new Date(this.date)
- }
- @State date: string = '2026-08-08'
- controller: CustomDialogController
- //起始年份
- @State startYear: number = 1970
- @State isLunar: boolean = false
- @State showFlag: Visibility = Visibility.Visible;
- @State isAutoCancel: boolean = false;
- @State selectedDate: Date = new Date(this.date)
- cancel?: (date: string) => void
- confirm?: (date: string, date1: Date) => void
- // 延迟关闭弹窗,让自定义的出场动画显示
- @State nowDate: Date = new Date()
- destroy() {
- this.showFlag = Visibility.Hidden
- setTimeout(() => {
- this.controller.close()
- }, anmDuration)
- }
- build() {
- Column() {
- Column() {
- Row() {
- Button('取消', { type: ButtonType.Normal }).backgroundColor(Color.White).fontColor(Color.Gray)
- .onClick(() => {
- if (this.cancel) {
- this.destroy();
- this.cancel(this.date)
- }
- })
- Button('确定', { type: ButtonType.Normal }).backgroundColor(Color.White).fontColor("#fff5b6dd")
- .onClick(() => {
- if (this.confirm) {
- this.destroy();
- this.date = this.nowDate.toString()
- this.confirm(this.date, this.nowDate)
- }
- })
- }.width('100%').justifyContent(FlexAlign.SpaceBetween)
- DatePicker({
- start: new Date('1970-1-1'),
- end: new Date('2100-1-1'),
- selected: this.selectedDate
- })
- .disappearTextStyle({ color: Color.Gray, font: { size: '16fp', weight: FontWeight.Bold } })
- .textStyle({ color: '#ff182431', font: { size: '16', weight: FontWeight.Normal } })
- .selectedTextStyle({ color: "#fff5b6dd", font: { size: '22fp', weight: FontWeight.Regular } })
- .lunar(this.isLunar)
- .onDateChange((value: Date) => {
- this.nowDate = value
- console.info('select current date is: ' + value.toString())
- })
- }
- }.width('100%').backgroundColor(Color.White).visibility(this.showFlag)
- // 定义进场出场转场动画效果
- .transition(TransitionEffect.OPACITY.animation({ duration: anmDuration })
- .combine(TransitionEffect.translate({ y: 100 })))
- }
- }
复制代码 2、HarmonyOS 体系图片组件Image加载当地资源读取目录方式?
体系在辨认以下实例时是如何根据相对路径取到绝对路径的
当地资源创建文件夹,将当地图片放入ets文件夹下的任意位置。Image组件引入当地图片路径,即可显示图片(根目录为ets文件夹)。
frameworks/core/image/image\_loader.cpp差异的的URL会创建差异的imageLoader,然后走对应的加载逻辑
好比这种写法;Image($r(“app.media.symbol”))会走ResourceImageLoader
3、HarmonyOS ArkTS 可否像kotin一下,可以在子线程中直接调用CoroutineScope.launch转到UI线程?
在子线程A中创建子线程B,想在子线程B中直接发消息给UI线程。肯定要先子线程B发消息给子线程A,子线程A收到消息后,再发消息给UI线程吗。有没有办法让子线程B直接发消息给UI线程大概说转到UI线程
可以用Emitter进行线程间通信,在UI线程吸收事件消息,刷新ui,文档如下:
https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/itc-with-emitter-V5
4、HarmonyOS hap包下载到手机上怎么安装?
hap包下载到手机上怎么安装。内部环境,流水线构建了应用的产物,得到hap包,下载到手机上,怎么安装呢。
现在不支持手动打开hap包安装应用。可以通过开放式测试,上架应用市场,指定测试职员,进行应用分发测试操作流程参考:https://developer.huawei.com/consumer/cn/doc/AppGallery-connect-Guides/agc-betatest-introduction-0000001071477284
如不想上架应用市场,进行企业内部测试可参考:https://developer.huawei.com/consumer/cn/doc/app/agc-help-harmonyos-internalrelease-0000001756878768
5、HarmonyOS overlay中,沉醉模式似乎无效 expandSafeArea,叨教overlay的扩展规则是怎样的呢?
基于navigation去扩展遮罩,自己自带安全地区扩展,但是遮罩并没有像期望一样覆盖全屏,叨教大概是什么缘故原由导致的呢?
navigation默认支持安全区避让特性(默认值为:expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])),以是改成expandSafeArea([])即可。
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |