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

早过忘川 提交于 2019-12-04 09:45:01
King of Masses

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

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)

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