我有一个EditText,我只希望在其中插入整数值。谁能告诉我该用哪个属性?
当前回答
您可以在XML中使用它
<EditText
android:id="@+id/myNumber"
android:digits="123"
android:inputType="number"
/>
or,
android:inputType="numberPassword" along with editText.setTransformationMethod(null); to remove auto-hiding of the number.
or,
android:inputType="phone"
您可以通过编程方式使用 editText.setInputType (InputType.TYPE_CLASS_NUMBER);
其他回答
如果有人想只使用数字从0到9 imeOptions启用,然后使用下面的行在您的EditText
android: inputType = " |没有数量"
这将只允许数字,如果你点击完成/键盘的下一个按钮,你的焦点将移动到下一个字段。
我需要捕捉按下键盘上的输入与TextWatcher。但我发现所有的数字键盘android:inputType="number"或"numberDecimal"或"numberPassword"等不允许我捕捉进入时,用户按下它。
我尝试了android:digits="0123456789\n",所有的数字键盘都开始使用Enter和TextWatcher。
所以我的方法是:
android:digits="0123456789\n"
android:inputType="numberPassword"
加上editText.setTransformationMethod(空)
多亏了barmaley和abhiank。
添加android:inputType="number"作为XML属性。
android:inputType="numberDecimal"
对我来说最简单
android:numeric="integer"
虽然这也更自定义
android:digits="0123456789"
推荐文章
- 以编程方式将EditText的输入类型从PASSWORD更改为NORMAL,反之亦然
- 如何在隐藏和查看密码之间切换
- 在Android上调整一个大的位图文件到缩放输出文件
- 如何更改Android版本和代码版本号?
- Android Studio突然无法解析符号
- 应用程序重新启动而不是恢复
- 如何设置整个应用程序在纵向模式?
- Android中文本的阴影效果?
- 以编程方式设置TextView的布局权重
- Android -如何覆盖“后退”按钮,所以它不完成()我的活动?
- 如何从通知点击发送参数到一个活动?
- 导航目标xxx对于这个NavController是未知的
- 使用ConstraintLayout均匀间距的视图
- 文件google-services错误。模块根文件夹中缺少Json。谷歌服务插件没有它就不能正常工作。
- 如何以编程方式创建ColorStateList ?