如何更改TextInput密码输入模式下passwordIcon的大小、颜色、位置

如何更改TextInput密码输入模式下passwordIcon的大小、颜色、位置

HarmonyOS
2024-07-22 12:19:50
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
janux

使用stack容器作为父容器,子容器使用image来实现自定义一个passwordIcon,此时即可对Image组件的位置、大小、颜色做出更改。

@Entry 
@Component 
struct TextInputExample { 
  @State text: string = '' 
  @State changeType: InputType = InputType.Password 
  @State isVisible: boolean = false 
  @State changeState: boolean = false 
  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 }) 
            .showPasswordIcon(false) 
            .width(336) 
            .height(56) // 设置内间距让输入内容不超过图标位置 
            .padding({ 
              right: 50 
            }) 
            .onChange((value: string) => { 
              this.text = value 
            }) 
          // Image覆盖passwordIcon实现 
          Image($r(this.isVisible ? 'app.media.visible' : 'app.media.Invisible')) 
            .margin({ 
              left: 280 
              // left: 200 
            }) 
            .backgroundColor('#E7E8EA') 
            .width(20) 
            .height(20) 
            .onClick(() => { 
              this.changeState = !this.changeState 
              this.isVisible = !this.isVisible 
              if (this.changeState) { 
                this.changeType = InputType.Normal 
              } else { 
                this.changeType = InputType.Password 
              } 
            }) 
        } 
      } 
    }.width('100%').height('100%').backgroundColor('#F1F3F5') 
  } 
}
分享
微博
QQ
微信
回复
2024-07-22 20:05:12
相关问题
触摸TextInput组件背景颜色如何更改
107浏览 • 1回复 待解决
TextInput组件输入状态隐藏光标
687浏览 • 1回复 待解决
TextInput怎么输入中文
2511浏览 • 0回复 待解决
text怎么更改部分文字颜色
6591浏览 • 1回复 待解决
如何获取元素位置大小
1812浏览 • 1回复 待解决
ohpm-repo上传产物如何跳过输入密码
425浏览 • 1回复 待解决
linear-gradient设置颜色起止位置
403浏览 • 1回复 待解决
录音时如何获取 当前输入音量大小
5246浏览 • 1回复 待解决
设置TextInput组件光标位置在起点
103浏览 • 1回复 待解决