HarmonyOS TextInput clearButton 位置问题?

如题:HarmonyOS TextInput clearButton 位置问题?

阅读 573
1 个回答

问题场景

TextInput 的clearButton 距离TextInput 的右边间距无法控制

目前textInput的cancelButton暂时不支持调整间距此场景可以通过自定义组件实现,以下是参考Demo

@Entry
@Component
struct TextInputExample {
  @State text: string = ''
  @State changeType:InputType = InputType.Number
  controller: TextInputController = new TextInputController()
  build() {
    Column() {
      Flex({direction: FlexDirection.Row}){
        Stack(){
          TextInput({ text: this.text, controller: this.controller })
            .type(this.changeType)
            .placeholderFont({ size: 16, weight: 400 })
            .width('100%')
            .height(56)
            .onChange((value: string) => { this.text = value })
          Image($r('app.media.startIcon'))
            .margin({ left: 290 })
            .width(20)
            .height(20)
            .onClick(() =>{
              this.text = ''
            })
        }
      }
    }.width('100%').height('100%').backgroundColor('#F1F3F5') } }
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进