【每日学点鸿蒙知识】弹窗封装成方法、Tab设置默认tabcontent、rawfile文件路径、默认组件宽高、不同状态颜色

1、HarmonyOS 弹窗封装成一个方法 在其他地方直接调用?

弹框场景更推荐使用promptAction.openCustomDialog,后续弹框也主要是基于promptAction做演进。开发者主要需要自定义弹框内容的buillder,使用参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-promptaction-V5

使用promptAction.openCustomDialog可以设置弹窗非模态(isModal: false)来控制点击弹窗外部区域不自动关闭

2、HarmonyOS Tabs组件设置默认的tabcontent不是0?

在使用tabs组件时,业务场景需要展示的tabcontent不是第一个,比如默认展示第三个tabcontent,需要怎么设置。

index:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-components-container-tabs-V5r'w

Tabs(value?: {barPosition?: BarPosition, index?: number, controller?: TabsController})

3、HarmonyOS $rawfile("index.html")中index.htm在项目哪个目录下放置?

如下图:

4、HarmonyOS 组件的宽高设置auto,不生效,默认父组件全部宽高?

当width设置auto时,如果水平方向上子组件以容器作为锚点,则auto不生效,垂直方向上同理。参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-container-relativecontainer-V5

复制代码
@Builder
heatmapExampleLayout() {
  RelativeContainer() {
    Image($r('app.media.startIcon'))
      .fitOriginalSize(true)
      .margin({ bottom: 10 })
      .id('example_img')
    // .alignRules({
    // left: { anchor: '__container__', align: HorizontalAlign.Start },
    // top: { anchor: '__container__', align: VerticalAlign.Top }
    // })

    Text(`事实上`)
      .fontColor(Color.Red)
      .fontSize(12)
      .id('example_less')
    // .alignRules({
    // left: { anchor: '__container__', align: HorizontalAlign.Start },
    // bottom: { anchor: '__container__', align: VerticalAlign.Bottom }
    // })

    Text(`测试`)
      .fontColor(Color.Blue)
      .fontSize(12)
      .id('example_more')
    // .alignRules({
    // right: { anchor: 'example_img', align: HorizontalAlign.End },
    // bottom: { anchor: '__container__', align: VerticalAlign.Bottom }
    // })
  }
  .padding({
    left: 8,
    right: 8,
    top: 5,
    bottom: 5
  })
  .margin({ left: 8, bottom: 12 })
  .border({
    width: 2,
    color: Color.White,
    radius: 8
  })
  .backgroundColor(Color.Gray)
  // .alignRules({
  // left: { anchor: '__container__', align: HorizontalAlign.Start },
  // bottom: { anchor: 'bottom_layout', align: VerticalAlign.Top }
  // })
  .width(`auto`)
  .height(`auto`)
}
5、HarmonyOS 按钮设置了不同状态下的字体颜色,但是都只显示Normal的颜色?

stateStyles接口只支持通用属性,fontColor不是通用属性,设置时不生效。对非通用属性的处理,建议使用attributeModifier,参考文档:

复制代码
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-attribute-modifier-V5#attributemodifier
相关推荐
遇到困难睡大觉哈哈11 小时前
HarmonyOS 公共事件机制介绍以及多进程之间的通信实现(9000字详解)
华为·harmonyos
幽蓝计划14 小时前
HarmonyOS NEXT仓颉开发语言实战案例:外卖App
开发语言·harmonyos
伍哥的传说14 小时前
鸿蒙系统(HarmonyOS)应用开发之实现电子签名效果
开发语言·前端·华为·harmonyos·鸿蒙·鸿蒙系统
Georgewu16 小时前
【HarmonyOS】应用开发拖拽功能详解
harmonyos
塞尔维亚大汉16 小时前
鸿蒙内核源码分析(构建工具篇) | 顺瓜摸藤调试鸿蒙构建过程
源码·harmonyos
Fanmeang19 小时前
OSPF高级特性之FRR
运维·网络·华为·ip·ospf·spf·frr
kumalab19 小时前
HarmonyOS ArkTS卡片堆叠滑动组件实战与原理详解(含源码)
华为·harmonyos
别说我什么都不会20 小时前
【OpenHarmony】鸿蒙开发之xml2jsDemo
harmonyos
HarmonyOS_SDK1 天前
HarmonyOS免密认证方案 助力应用登录安全升级
harmonyos
zhanshuo1 天前
鸿蒙操作系统核心特性解析:从分布式架构到高效开发的全景技术图谱
harmonyos