問題描述
提前感謝您的幫助.
我正在開發一個用于研究目的的 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模板網!