Android 数字密码字段 [英] Android numeric password field

查看:24
本文介绍了Android 数字密码字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 EditText 字段,它需要是一个数字密码字段.在纵向模式下一切正常;不在风景中.当用户选择 EditText 字段时,UI 会放大该字段,并且当我键入时,所有字符都可见.

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 zooms into the field and when I type all the characters are visible.

我还需要一个数字键盘.我尝试将输入类型设置为文本密码|数字.如果我删除数字"选项一切正常;否则不行.

I need a numeric keyboard also. I tried setting the input type to text password|number. If I remove "number" option everything works right; otherwise no.

有什么建议吗?

推荐答案

这个问题可以在不使用已弃用的 android:password 的情况下解决.使用以下代码片段,但不要颠倒调用顺序:

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());

这篇关于Android 数字密码字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆