Android 安卓有数字键盘吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1654901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does android have a numeric keypad?
提问by Tawani
Is there a way in android to invoke a numeric only keypad, i.e. a virtual keypad that contains only the numbers 0 to 9 and a "." sign?
android 中是否有一种方法可以调用仅数字键盘,即仅包含数字 0 到 9 和“.”的虚拟键盘。标志?
回答by Peter Boughton
Try doing android:inputType="phone"
?
尝试做什么android:inputType="phone"
?
回答by Dimitar Dimitrov
Basically, you need what Peter Boughton said.
基本上,您需要 Peter Boughton 所说的内容。
More generally, if you need to invoke different type of keyboard, depending on the input you expect on your EditText component, you should use the IMF (Input Media Framework) and different IMEs (Input Media Editors).
更一般地,如果您需要调用不同类型的键盘,根据您在 EditText 组件上期望的输入,您应该使用 IMF(输入媒体框架)和不同的 IME(输入媒体编辑器)。
You can customize not only the input symbols, but also the layout of the keyboard in your application, auto-completion and other options.
您不仅可以自定义输入符号,还可以自定义应用程序中的键盘布局、自动完成和其他选项。
You may want to read this post in the Android Developers Blog: Updating Applications for On-screen Input Methods
您可能希望阅读 Android 开发者博客中的这篇文章: 更新屏幕输入法的应用程序
回答by Mark F Guerra
If you're talking about restricting input to 0-9 + "." for an EditText box, I use the android:numeric="decimal" attribute in the layout XML.
如果您正在谈论将输入限制为 0-9 + "." 对于 EditText 框,我在布局 XML 中使用 android:numeric="decimal" 属性。
<EditText android:numeric="decimal" />
If you're working with dynamically generated EditText views, the relevant method to call on it is setKeyListener()
如果您正在使用动态生成的 EditText 视图,调用它的相关方法是 setKeyListener()
回答by Soups Ranjan
Make sure you only have:
<EditText android:numeric="decimal" />
确保您只有:
<EditText android:numeric="decimal" />
and not both:
<EditText android:numeric="decimal"
android:digits="0123456789." />
而不是两者:
<EditText android:numeric="decimal"
android:digits="0123456789." />
The latter, ie using both numeric and digits was not working for me. However, using only numeric works.
后者,即同时使用数字和数字对我不起作用。但是,仅使用数字有效。
回答by Munish Thakur
<EditText android:numeric="decimal" />
only does not affect keypad to convert into decimal. Instead, use:
仅不影响键盘转换为十进制。相反,使用:
<EditText android:inputType="phone" android:numeric="decimal"></EditText>
This will show the numeric keypad only.
这将仅显示数字键盘。