【每日学点鸿蒙知识】placement设置top、组件携带自定义参数、主动隐藏输入框、Web设置字体、对话框设置全屏宽

1、popup组件placement设置top没有生效?

可以用offset属性将popup往下边偏移一下 来规避

2、组件携带自定义参数的接口是哪个?

参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-custom-property-V5#customproperty

customProperty

复制代码
customProperty(name: string, value: Optional<Object>)

设置组件的自定义属性。自定义组件不支持设置自定义属性。
卡片能力: 从API version 12开始,该接口支持在ArkTS卡片中使用。

3、HarmonyOS 如何主动隐藏输入弹框?

可以给外层容器添加个点击事件,在点击事件中调用controller.stopEditing()方法移除输入框焦点即可隐藏键盘

复制代码
@Entry
@Component
struct TextInputExample {
  controller: TextInputController = new TextInputController();

  build() {
    Column() {
      TextInput({ controller: this.controller }) }
    .width('100%') .height('100%')
    .onClick(()=>{ this.controller.stopEditing();
    })
  }
}
4、HarmonyOS webview字体大小设置?

使用defaultFontSize设置网页的默认字体大小,参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-web-V5#ZH-CN_TOPIC_0000001930757269__defaultfontsize9

5、HarmonyOS promptAction.openCustomDialog 弹窗如何宽度设置全屏宽?

目前promptAction.openCustomDialog 设置width('100%'), 系统会默认所在窗口宽度 - 左右 16vp

width参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-promptaction-V5#ZH-CN_TOPIC_0000001884757698__customdialogoptions11<br>

demo:

复制代码
import promptAction from '@ohos.promptAction';
import display from '@ohos.display'

@Entry
@Component
struct Index {
  @State message: string = 'Hello World';

  build() {
    Button('点我').onClick(() => {
      DialogUtils.show(this)
    })
  }
}

@Component
export struct TestComponent {
  build() {
    Row() {
      Text('弹窗内组件1弹窗内组件2弹窗内组件3弹窗内组件4弹窗内组件5弹窗内组件')
        .height(200)
        .textAlign(TextAlign.Center)
    }
  }
}

export class DialogUtils {
  public static createOption(builder: CustomBuilder) {
    const option: promptAction.CustomDialogOptions = {
      builder: builder,
      isModal: true,
      alignment: DialogAlignment.Bottom,
      cornerRadius: 0,
      backgroundColor: Color.Red,
      width: "110%",
      autoCancel: false,
    }
    return option
  }

  public static show(context: Object,) {
    promptAction.openCustomDialog(DialogUtils.createOption(buildComp.bind(context)))
  }
}

@Builder
function buildComp() {
  TestComponent()
}
相关推荐
蜗牛前端14 分钟前
codex 全流程开发上线的高颜值礼簿小程序
前端·微信小程序
大龄秃头程序员1 小时前
我在图文流 App 里落地双层缓存、弱网降级与 OOM 治理
前端
TT_Close1 小时前
别劝退了!5秒搞定 Flutter 鸿蒙 FVM 起跑线
flutter·harmonyos·visual studio code
老王以为1 小时前
React Renderer 分离的多平台架构
前端·react native·react.js
hunterandroid1 小时前
Kotlin Coroutines 与 Flow:让异步任务更清晰
前端
Bigger2 小时前
从零搭建 AI 代码审查服务:一份前端也能看懂的 Python 学习笔记
前端·ci/cd·ai编程
lichenyang4532 小时前
JSAPI、NAPI、Biz、Imp:ASCF Demo 如何真正调用系统能力和 C++ 能力
前端
lichenyang4532 小时前
IPC、JSVM、UIThread、libuv:ASCF 架构图里最容易混的几个词
前端
用户059540174462 小时前
Redis记忆存储故障恢复测试踩坑实录:手动测试让我漏掉了2个一致性Bug
前端·css
用户2136610035722 小时前
Vue2脚手架工程化与Axios集成
前端·vue.js