输入框组件,是否有输入内容后自动弹出的删除按钮X,还是需要自己用代码实现?

如题:输入框组件,是否有输入内容后自动弹出的删除按钮X,还是需要自己用代码实现?

阅读 494
1 个回答

解决措施暂时没有相关接口,可以通过自定义来实现参考代码

Stack({ alignContent: Alignment.End }) {
  TextInput({ text: $$this.textValue, placeholder: "请输入密码", controller: this.controller })
    .type(InputType.Normal)
    .onChange((v) => {
      console.log(this.textValue)
    })
  Image($r("app.media.startIcon")).width(20).height(20).margin({
    right: 8
  }).onClick(() => {
    this.textValue = ""
    console.log(this.textValue)
  })
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进