【每日学点鸿蒙知识】弹窗封装成方法、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
相关推荐
Demisse9 小时前
[华为eNSP] OSPF综合实验
网络·华为
Georgewu10 小时前
【HarmonyOS 5】桌面快捷方式功能实现详解
harmonyos
娅娅梨11 小时前
HarmonyOS-ArkUI 自定义弹窗
华为·harmonyos·arkts·arkui
陈奕昆12 小时前
3.3 HarmonyOS NEXT原子化服务开发:卡片设计、轻量部署与场景化编排实战
华为·harmonyos
上海张律师15 小时前
鸿蒙ArkTS+ArkUI仿微信消息列表页制作
harmonyos
Humbunklung20 小时前
关于华为仓颉编程语言
华为·cangjie
王二蛋与他的张大花1 天前
HarmonyOS运动开发:如何用mpchart绘制运动配速图表
harmonyos
程序员小刘1 天前
【HarmonyOS 5】生活与服务开发实践详解以及服务卡片案例
华为·生活·harmonyos