Show the password with EditText

前端 未结 12 918
旧时难觅i
旧时难觅i 2021-01-30 22:04

I use an EditText to enter password. And a CheckBox to show password or not. Below function is the part:

public void ShowPassword() {
    if (cb.isChecked()) {
          


        
12条回答
  •  佛祖请我去吃肉
    2021-01-30 22:47

    This is not an answer,

    Answer already given and accepted..

    I just want to clarify about 129

    password.setInputType(129);
    

    is Actually,

    password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    

    '|' is not a pipe, it's a bitwise OR. It takes two binary numbers and if either of the bits of equal value are 1,

    How this relates to the input type: Each of the InputTypes are actually just ints. TYPE_CLASS_TEXT is 1, and TYPE_TEXT_VARIATION_PASSWORD is 128 (or 10000000).

    Perform a bitwise OR on them:

    00000001
    
    10000000
    
    ------------
    
    10000001 which is 129.
    

    Try entering input.setInputType(129); instead, you'll see it'll work. :)

提交回复
热议问题