【每日学点鸿蒙知识】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()
}
相关推荐
独泪了无痕10 小时前
使用Fetch API 探索前后端数据交互
前端·http·交互设计
css趣多多10 小时前
别名路径的知识点
前端
靓仔建12 小时前
Vue3导入组件出错does not provide an export named ‘user_setting‘ (at index.vue:180:10)
开发语言·前端·typescript
EnoYao12 小时前
我写了一个团队体检报告 Skill,把摸鱼的同事扒出来了😅
前端·javascript
梁正雄12 小时前
Python前端-2-css练习
前端·css·python
清汤饺子12 小时前
用 Cursor 半年了,效率还是没提升?是因为你没用对这 7 个功能
前端·后端·cursor
深海呐12 小时前
鸿蒙 Video组件的基本使用(HarmonyOS-VideoView)
华为·harmonyos·harmonyos video·harmonyos 视频播放·harmonyos 播放器·harmonyos 播放视频
蓝莓味的口香糖12 小时前
【vue3】组件的批量全局注册
前端·javascript·vue.js
wefly201712 小时前
开发者效率神器!jsontop.cn一站式工具集,覆盖开发全流程高频需求
前端·后端·python·django·flask·前端开发工具·后端开发工具
独泪了无痕13 小时前
自动导入 AutoImport:告别手动引入依赖,优化Vue3开发体验
前端·vue.js·typescript