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?

Onorio Catenacci
  • 14,928
  • 14
  • 81
  • 132

2 Answers2

17

The right way is:

editText {
    inputType = TYPE_CLASS_TEXT or TYPE_TEXT_VARIATION_PASSWORD
}
yanex
  • 1,101
  • 8
  • 10
  • 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? – ZooS Nov 30 '17 at 14:19
  • @ZooS You can use the `TextInputEditText` provided by the Android Support library: https://medium.com/@moyinoluwa/password-visibility-toggle-android-support-library-revision-24-2-0-98b422087e5a. – yanex Dec 25 '17 at 17:23
3

Actually you have to Reference it from InputType like this:

editText { 
    inputType = InputType.TYPE_TEXT_VARIATION_PASSWORD
}
Eefret
  • 4,724
  • 4
  • 30
  • 46