HarmonyOS TextInput密码类型

在TextInput设置InputType.Password密码类型下,是否有api能让开发者控制密码是否可见,不是PasswordIcon这种形式,passwordIcon目前只能设置图标,不支持设置大小

HarmonyOS
2024-12-18 15:24:20
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

可以自定义设置控制密码是否可见的图标,参考如下demo:

@Entry
@Component
struct TextInputExample {
  @State text: string = ''
  @State password: string = '';
  @State positionInfo: CaretOffset = { index: 0, x: 0, y: 0 }
  controller: TextInputController = new TextInputController()
  @State isShowPassword:boolean = false;

  build() {
    Column() {
      TextInput({ text: this.text, placeholder: 'input your word...', controller: this.controller })
        .placeholderColor(Color.Grey)
        .placeholderFont({ size: 14, weight: 400 })
        .caretColor(Color.Blue)
        .width('95%')
        .height(40)
        .margin(20)
        .fontSize(14)
        .fontColor(Color.Black)
        .inputFilter('[a-z]', (e) => {
          console.log(JSON.stringify(e))
        })
        .onChange((value: string) => {
          this.text = value
        })
      // 密码输入框
      Row(){
        // if(this.isClick === true){
        TextInput({text: $$this.password, placeholder: 'input your password...' })
          .width('95%')
          .height(40)
          .margin(8)
          .type(this.isShowPassword ? InputType.Normal : InputType.Password)
          .maxLength(9)
          .showPasswordIcon(false)
        Image(this.isShowPassword ? $r('app.media.ic_personal_normal'): $r('app.media.ic_personal_focus'))
          .width('25vp')
          .height('25vp')
          .margin({right:'80vp',bottom:'50%'})
          .position({x:'85%',y:15})
          .onClick(()=>{
            this.isShowPassword = !this.isShowPassword
          })
      }
      .width('100%')

    }.width('100%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.

两种不同的passwordicon对应的需要不同的键盘模式,但是不同的键盘之间进行切换肯定会存在差异,没办法改善

分享
微博
QQ
微信
回复
2024-12-18 16:34:23
相关问题
HarmonyOS 密码输入框
783浏览 • 1回复 待解决
HarmonyOS 有没有密码控件?
858浏览 • 1回复 待解决
HarmonyOS 手势密码组件
676浏览 • 1回复 待解决
HarmonyOS 密码输入组件
595浏览 • 1回复 待解决
HarmonyOS 密码保险箱
1106浏览 • 1回复 待解决
HarmonyOS目前支持设置手势密码
900浏览 • 1回复 待解决
HarmonyOS 自动保存账号密码
751浏览 • 1回复 待解决
HarmonyOS TextInput问题
441浏览 • 1回复 待解决
HarmonyOS 图案密码锁组件怎么实现
1381浏览 • 1回复 待解决
HarmonyOS HAR publish时需要的密码问题
1251浏览 • 1回复 待解决
HarmonyOS 主动弹保存帐号密码
616浏览 • 1回复 待解决