【每日学点鸿蒙知识】弹窗封装成方法、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
相关推荐
python算法(魔法师版)3 小时前
.NET 在鸿蒙系统上的适配现状
华为od·华为·华为云·.net·wpf·harmonyos
bestadc4 小时前
鸿蒙 UIAbility组件与UI的数据同步和窗口关闭
harmonyos
枫叶丹45 小时前
【HarmonyOS Next之旅】DevEco Studio使用指南(二十二)
华为·harmonyos·deveco studio·harmonyos next
ax一号街阿楠7 小时前
华为FAT AP配置 真机
网络·华为·智能路由器
吗喽对你问好7 小时前
华为5.7机考第一题充电桩问题Java代码实现
java·华为·排序
乱世刀疤9 小时前
深度 |国产操作系统“破茧而出”:鸿蒙电脑填补自主生态空白
华为·harmonyos
博睿谷IT99_14 小时前
华为HCIP-AI认证考试版本更新通知
人工智能·华为
连续讨伐14 小时前
ensp的华为小实验
华为
沙振宇15 小时前
【Web】使用Vue3开发鸿蒙的HelloWorld!
前端·华为·harmonyos
嘿嘿-g1 天前
华为IP(6)
网络·tcp/ip·华为