Android numeric password field

后端 未结 8 1633
春和景丽
春和景丽 2020-12-05 00:15

I have an EditText field which needs to be a numeric password field. Everything works OK in portrait mode; not in landscape. When the user selects the EditText field, the UI

相关标签:
8条回答
  • 2020-12-05 00:38

    I think you should use android:password="true" and android:numeric="integer". But as the Android documentation states (in R.attr.html, not in the TextView docs), these are deprectated and you should use android:inputType. inputType takes flag, so you can mix mulitple possibilities. And I think android:inputType="number | password" should work for you.

    You should specify android:password="true" if you want to support older devices too.

    0 讨论(0)
  • 2020-12-05 00:40

    This problem can be solved without using deprecated android:password. Use the following code snippet, but do not reverse the sequence of calls:

        EditText editText = (EditText) findViewById(R.id.MyEditText);
        editText.setInputType(InputType.TYPE_CLASS_NUMBER);
        editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
    
    0 讨论(0)
提交回复
热议问题