在Android中以编程方式在软输入键盘上禁用语音到文本按钮(麦克风) [英] Disable speech to text button (Micro phone) on soft input keyboard in android programmatically

查看:336
本文介绍了在Android中以编程方式在软输入键盘上禁用语音到文本按钮(麦克风)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

预先感谢您的帮助.

我出于研究目的而开发了一个android应用程序,需要禁用软输入键盘上的语音转文本按钮.原因是由于我正在开发的应用程序使用麦克风后出现的并发问题.我了解,对于一般应用程序,禁用键通常被认为是不可能的(因为用户可以更改默认键盘).我知道将使用默认键盘.

I am developing an android application for research purposes and need to disable the speech to text button on the soft input keyboard. The reason for this is due to concurrency issues that arise since the application I am developing uses the microphone. I understand that for a general application disabling keys is generally seen as impossible (since users may change default keyboards). I know for a fact that the default keyboard will be used.

考虑到这一点,可以禁用某些键吗?我相信至少我应该能够指定输入类型,以便隐藏麦克风按钮.我之所以这样说是因为,如果我在设置中(不是以编程方式,而是以用户手动方式)禁用了对文本的语音显示,则会从键盘上删除麦克风图标.我愿意接受任何可能的解决方案(不使用默认键盘除外),因为此应用程序不会出现在Play商店中.

With this in mind is it possible to disable certain keys? I believe that at the least I should be able to specify the input type such that the microphone button is hidden. I say this because if I disable speech to text in the settings (not programmatically, but manually as a user) the microphone icon is removed from the keyboard. I'm open to any possible solution (with the exception of not using the default keyboard) as this application will not appear on the play store.

推荐答案

您不能通过用户设备中已经存在的预定义键盘以外的其他任何方式强制用户输入.

You can't force the user input through anything other than pre-defined keyboards that already exist in the user's device.

解决此问题的唯一方法是编写自己的自定义即时键盘,这是一个非常糟糕的主意.

The only way you could get around this is by programming your own custom, on-the-fly keyboard, and that is a very bad idea.

只需在要查看的EditText中使用XML声明以编程方式禁用语音输入即可.您可以使用以下属性进行操作:

Just disable voice input programmatically by using XML declarations in the EditText you're looking at. You can do this with the attribute:

android:privateImeOptions="nm"   // nm stands for No Microphone.

如果要以编程方式进行设置,可以尝试以下操作::

If you want to set it programmatically you can try this::

        // deprecated i guess
        edt_txt.setPrivateImeOptions("nm");   
         // this one is new but it works only with Google Keyboard.
         edt_txt.setPrivateImeOptions("com.google.android.inputmethod.latin.noMicrophoneKey"); 

您可以在CVS格式中组合PrivateImeOptions参数中的值,因此最好的选择是使用:

You can combine values in PrivateImeOptions parameter in CVS form so best option is to use:

                edt_txt.setPrivateImeOptions("nm,com.google.android.inputmethod.latin.noMicrophoneKey"); 

此处看一下,看看是否可以找到您想要的东西.

Take a look through here and see if you can find what you're looking for.

有关Google键盘的更多信息

More info about Google Keyboard here -> look for method setOptions

这篇关于在Android中以编程方式在软输入键盘上禁用语音到文本按钮(麦克风)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆