简体   繁体   English

Kotlin EditText以编程方式显示/隐藏密码

[英]Kotlin EditText show/hide password programmatically

I know how to do this on Java. 我知道如何在Java上执行此操作。 I copied and paste the code from Java to Kotlin and Android Studio changed to this: 我将代码从Java复制并粘贴到Kotlin,Android Studio更改为:

auth_password_text.setInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD)

But I'm receiving a message (grey not yellow like warning) 但我收到一条消息(灰色不像黄色一样警告) 在此输入图像描述

I search and found only java and react native answer but not was the best/right way to do this in Kotlin. 我搜索并发现只有java并反应原生答案,但不是在Kotlin中做到这一点的最佳/正确方法。

Thank you in advance! 先感谢您!

For any warning or suggestion reported by the IDE, you can press Alt-Enter, and in most cases (including this one) the IDE will suggest a quickfix that will automatically apply the suggested change. 对于IDE报告的任何警告或建议,您可以按Alt-Enter,在大多数情况下(包括此)IDE将建议一个自动应用建议更改的quickfix。

In this case, it will change the call of a Java setter to a Kotlin property access: 在这种情况下,它会将Java setter的调用更改为Kotlin属性访问:

auth_password_text.inputType = ...

In Kotlin you can set some properties accessing directly variable instead of calling setter method, that's the meaning of the warning you are getting. 在Kotlin中,你可以设置一些属性直接访问变量而不是调用setter方法,这就是你得到的警告的含义。

You can remove warning like this: 你可以删除这样的警告:

auth_password_text.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM