我有一个EditText字段,需要是一个数字密码字段.在肖像模式下一切正常; 不在风景中.当用户选择EditText字段时,UI会缩放到该字段中,当我键入时,所有字符都可见.
我也需要一个数字键盘.我尝试将输入类型设置为文本密码.如果我删除"数字"选项一切正常; 否则没有.
有什么建议?
Vik*_*šan 61
可以在不使用弃用的情况下解决此问题android:password.使用以下代码段,但不要反转调用顺序:
EditText editText = (EditText) findViewById(R.id.MyEditText);
editText.setInputType(InputType.TYPE_CLASS_NUMBER);
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
Run Code Online (Sandbox Code Playgroud)
rob*_*ick 17
我找到的需要隐藏的数字文本条目(密码样式)的最简单的解决方案是使用: android:inputType="numberPassword"
完整的例子对我有用:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/MyLargeTextBox"
android:background="@android:drawable/editbox_background_normal"
android:id="@+id/txtWebServicePIN"
android:layout_row="3"
android:layout_column="2"
android:layout_columnSpan="2"
android:minWidth="100dp"
android:maxWidth="100dp"
android:inputType="numberPassword"
android:maxLength="6"/>
Run Code Online (Sandbox Code Playgroud)
要解决在横向模式全屏编辑器中显示密码的问题(如Marcus所述),您可以添加以下行以禁用全屏编辑器:
editText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
Run Code Online (Sandbox Code Playgroud)
您可能还希望将字体更改为等宽字体以更好地模拟文本密码行为:
editText.setTypeface(Typeface.MONOSPACE);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
32592 次 |
| 最近记录: |