Canato
Canato

Reputation: 3978

Kotlin EditText show/hide password programmatically

I know how to do this on Java. I copied and paste the code from Java to Kotlin and Android Studio changed to this:

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) enter image description here

I search and found only java and react native answer but not was the best/right way to do this in Kotlin.

Thank you in advance!

Upvotes: 2

Views: 5153

Answers (2)

AlexTa
AlexTa

Reputation: 5251

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.

You can remove warning like this:

auth_password_text.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD

Upvotes: 6

yole
yole

Reputation: 97268

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.

In this case, it will change the call of a Java setter to a Kotlin property access:

auth_password_text.inputType = ...

Upvotes: 4

Related Questions