以编程方式在android中的软输入键盘上禁用语音到

时间:2023-03-29
本文介绍了以编程方式在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 键盘的更多信息 这里 -> 寻找方法 setOptions

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

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

上一篇:UI键盘类型 下一篇:在 iOS 9 Shortcut Bar only 模式下,与键盘顶部对齐的

相关文章

最新文章