【每日学点鸿蒙知识】弹窗封装成方法、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
相关推荐
花先锋队长6 小时前
鸿蒙生态日日新,鸿蒙原生版支付宝下载量突破230万
华为·harmonyos
星之卡比*7 小时前
前端知识点---库和包的概念
前端·harmonyos·鸿蒙
别说我什么都不会8 小时前
使用Multipass编译OpenHarmony工程
操作系统·嵌入式·harmonyos
轻口味11 小时前
【每日学点HarmonyOS Next知识】多继承、swiper容器、事件传递、滚动安全区域、提前加载网络图片
华为·harmonyos·harmonyosnext
zhgjx-dengkewen11 小时前
华为eNSP:实验 OSPF单区域
运维·网络·华为·智能路由器
别说我什么都不会11 小时前
鸿蒙轻内核M核源码分析系列二一 05 文件系统FatFS
操作系统·嵌入式·harmonyos
Georgewu12 小时前
【HarmonyOS Next】鸿蒙应用故障处理思路详解
前端·vue.js·harmonyos
盖世栗子12 小时前
HarmonyOS中Image组件的缩放模式
harmonyos
幽蓝计划16 小时前
HarmonyOS Next开发教程之地图定位
harmonyos
轻口味20 小时前
【每日学点HarmonyOS Next知识】Web交互、列表拖拽、横屏后布局、Event序列问题、Scroll与Web组合
前端·交互·harmonyos·harmonyosnext