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

前端 未结 3 972
你的背包
你的背包 2021-01-06 10:20

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

相关标签:
3条回答
  • 2021-01-06 11:04

    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

    0 讨论(0)
  • 2021-01-06 11:05

    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)

    0 讨论(0)
  • 2021-01-06 11:07

    Just use this in your editText on the layout file:

    android:imeOptions="flagNoPersonalizedLearning"
    
    0 讨论(0)
提交回复
热议问题