How Can I Mask A Password With Anko?
Asked Answered
T

2

5

I realize Anko (and Kotlin) are both pretty cutting edge but I was hoping someone might be able to give me a little guidance on this. This is just a learning project for me, of course.

I've got the following Kotlin code (using Anko) only very slightly modified from the sample code:

verticalLayout {
    padding = dip(30)
    val name = editText {
        hint = "Name"
        textSize = 24f
    }
    val password = editText {
        hint = "Password"
        textSize = 24f
        inputType = android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD
    }
    button("Login") {
        textSize = 26f
        onClick {
        toast("Good afternoon, ${name.text}!")
        }
    }
}

Everything's building and displaying but I can't seem to get the password editText to mask the input as I'm typing it in. What am I missing?

Twinberry answered 1/5, 2015 at 20:36 Comment(0)
C
17

The right way is:

editText {
    inputType = TYPE_CLASS_TEXT or TYPE_TEXT_VARIATION_PASSWORD
}
Coe answered 1/5, 2015 at 21:23 Comment(2)
This masks the password, but how do I add the visibility toggle button at the end of the password input? Do I have to implement it as a separate button?Dressel
@Dressel You can use the TextInputEditText provided by the Android Support library: medium.com/@moyinoluwa/….Coe
Y
3

Actually you have to Reference it from InputType like this:

editText { 
    inputType = InputType.TYPE_TEXT_VARIATION_PASSWORD
}
Yvonneyvonner answered 21/3, 2016 at 16:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.