如何在数字 EditText 上启用语音输入?
我想利用 Android 的功能来接受配置为数字输入的 EditText 控件上的语音输入。我希望当控件获得焦点时弹出数字键盘。我使用了以下 xml:
<EditText
android:id="@+id/edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:numeric="decimal"
/>
这会导致数字和符号键盘按预期显示,但没有语音输入按钮。如果我将键盘切换到字母数字键,则会显示语音输入按钮,但它被禁用。
如果我删除 android:numeric="decimal" 属性,则会出现常规 abc 键盘并启用语音,如果我说出“一八十二点六六”之类的数字,它就会工作并在编辑文本框中显示 182.66。
我到处寻找某种方法来启用“仅十进制”语音输入。我在 EditText 或 TextView 上找不到任何与语音输入有关的属性。
有人可以帮忙吗?我宁愿不使用语音识别意图,如果可以避免的话,我必须自己做所有事情(尽管这将是一个有趣的学习项目!)
I would like to leverage Android's ability to accept voice input on an EditText control that is configured for numeric input. I would like the numeric keyboard to pop up when the control gets focus. I used the following xml:
<EditText
android:id="@+id/edittext"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:numeric="decimal"
/>
This causes the numeric and symbol keyboard to appear as expected, but there is NO voice input button. If I switch the keyboard to the alphanumeric keys, the voice input button is displayed, but it's disabled.
If I remove the android:numeric="decimal" attribute, the regular abc keyboard appears and voice is enabled, and if I speak a number like, "one eighty two point six six", it works and displays 182.66 in the edittext box.
I have searched high and low for some way to enable "decimal only" voice input. I haven't been able to find any attributes on either EditText or TextView that have to do with voice input.
Can anyone help? I would rather not use the voice recognition intent and have to do everything myself if I can avoid it (although it would be a fun learning project!)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为有任何开箱即用的方法可以让它按照你想要的方式工作。我猜最快的路径是将键盘设置为十进制,然后提供您自己的语音输入按钮。一旦服务器返回给您它认为听到的字符串,则只需验证它是否是一个数字,然后将其放入编辑文本中(如果是)。
I don't think there is going to be any out of the box way to make it work like you want. I would guess that the quickest path is set the keypad for decimal then supply your own button for voice input. Once the server gives you back the String that it thinks it heard then just validate that it is a number and put it into the edit text if so.