为什么模拟器虚拟键盘上的某些字母在 Android EditText 中显示数字(输入类型为“数字”)?
我的 Android 应用程序中有一个带有 inputtype=number 的 EditText 小部件。它确实限制字符只能按数字输入。但是,当我在模拟器的键盘上键入某些字母键(不是全部)时,我会看到编辑框中出现数字。例如,输入“F”会在编辑框中输入“6”,输入“D”会输入“5”等。为什么会发生这种情况?
——罗施勒
I have an EditText widget in my Android application with inputtype=number. It does restrict character to entry by number. However, when I type certain alphabetic keys on the emulator's keypad (not all of them) I see numbers appear in the edit box. For example, typing an "F" puts a "6" in the edit box, "D" puts a "5", etc. Why is this happening?
-- roschler
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我看到发生了两件事,具体取决于您使用的是模拟器还是手机,以及 SDK 版本:
出现完整键盘(较旧的 SDK)。行为正是您所说的:您只能键入数字,但也可以键入某些字符,并将其转换为数字。 Aleadam 所说的解释了这种行为。
软电话键盘(据我所知,主要在现代 SDK 和电话上)。典型的电话键盘出现...“2ABC”、“3CDE”等...
在这两种情况下,您都会看到,实际上只能输入数字,这正是我们想要的。例如,在首选项屏幕中,您可以完美地将
Object newValue
转换为 Integer,并且不会出现任何问题。我经常这样做,不用担心!
I've seen two things happen, depending if you're on the emulator or on the phone, and depending on the SDK version:
The full keyboard appears (older SDKs). The behavior is exactly what you said: you can only type numbers, but certain characters can also be typed, and are translated to numbers. That behavior is explained by what Aleadam said.
The soft phone keypad (mostly on modern SDKs and phones, as far as I've seen). The typical phone keypad appears... "2ABC", "3CDE" and so on...
On both situations, you will see that, in fact, only numbers can be entered, which is what we want. As an example, in preference screen, you can perfectly cast the
Object newValue
into a Integer and you won't have any problems.I do that all the time, don't worry!
它模拟也可用于拨号的纵向键盘。您的特定小部件没有任何问题:)
It emulates the portrait keyboards that can be used to dial numbers also. Nothing wrong with your particular widget :)
如果启用该标签,模拟器键盘将像 T9 一样工作。
ABC 将是 2
DEF 将为 3
等等
都是正常的,不是bug!
If you enable that tag the emulator keyboard works like a T9.
ABC will be 2
DEF will be 3
etc.
It's normal, it's not a bug!