【每日学点鸿蒙知识】弹窗封装成方法、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
相关推荐
搞瓶可乐3 小时前
鸿蒙ArkUI实战之组件;Text组件,Image组件,Button组件,Span组件和TextInput组件的使用场景及使用方法
华为·harmonyos·鸿蒙系统·arkui·组件化开发·基础组件使用
九丘教育4 小时前
【仓颉 + 鸿蒙 + AI Agent】CangjieMagic框架(15):NaiveExecutor
人工智能·华为·harmonyos
搞瓶可乐8 小时前
鸿蒙ArkUI实战之TextArea组件、RichEditor组件、RichText组件、Search组件的使用
华为·harmonyos·arkui·搜索框·富文本组件·富文本输入框·鸿蒙原生api
孤寂码农_defector8 小时前
鸿蒙系统的 “成长烦恼“:生态突围与技术迭代的双重挑战
macos·华为·objective-c·cocoa·harmonyos
别说我什么都不会9 小时前
【仓颉三方库】 数据解析——TOML4CJ
harmonyos
鸿蒙布道师10 小时前
鸿蒙NEXT开发LRUCache缓存工具类(单例模式)(ArkTs)
android·ios·华为·harmonyos·arkts·鸿蒙系统·huawei
城中的雾11 小时前
HarmonyOS Next 编译之如何构建不同包名应用
harmonyos·arkts
别说我什么都不会11 小时前
【仓颉三方库】 数据解析—— jwt4cj
harmonyos
周胡杰13 小时前
鸿蒙-跨设备互通,设备互通提供跨设备的相机、扫描、图库访问能力,平板或2in1设备可以调用手机的相机、扫描、图库等功能。
数码相机·华为·自动化·电脑·harmonyos·鸿蒙·鸿蒙系统
SuperHeroWu713 小时前
【HarmonyOS 5】VisionKit人脸活体检测详解
华为·harmonyos·人脸活体检测·visionkit