Disable speech to text button (Micro phone) on soft input keyboard in android programmatically

怎甘沉沦 提交于 2019-12-06 05:31:42

问题


Thanks in advance for the help.

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.

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.


回答1:


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.

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"); 

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.

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




回答2:


To disable microphone button on multiple keyboard. Use property

android:privateImeOptions="nm"

But it will not work for Gboard(google native keyboard)

To disable on microphone on Gboard use

android:privateImeOptions="nm" editText.setImeOptions(IME_FLAG_NO_PERSONALIZED_LEARNING)



来源:https://stackoverflow.com/questions/32263554/disable-speech-to-text-button-micro-phone-on-soft-input-keyboard-in-android-pr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!