問(wèn)題描述
提前感謝您的幫助.
我正在開(kāi)發(fā)一個(gè)用于研究目的的 android 應(yīng)用程序,并且需要禁用軟輸入鍵盤上的語(yǔ)音轉(zhuǎn)文本按鈕.其原因是由于我正在開(kāi)發(fā)的應(yīng)用程序使用麥克風(fēng)而出現(xiàn)的并發(fā)問(wèn)題.我知道對(duì)于一般應(yīng)用程序,禁用鍵通常被認(rèn)為是不可能的(因?yàn)橛脩艨赡軙?huì)更改默認(rèn)鍵盤).我知道將使用默認(rèn)鍵盤.
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.
考慮到這一點(diǎn),是否可以禁用某些鍵?我相信至少我應(yīng)該能夠指定輸入類型,以便隱藏麥克風(fēng)按鈕.我這樣說(shuō)是因?yàn)槿绻以谠O(shè)置中禁用語(yǔ)音到文本(不是以編程方式,而是作為用戶手動(dòng)),麥克風(fēng)圖標(biāo)就會(huì)從鍵盤上移除.我愿意接受任何可能的解決方案(不使用默認(rèn)鍵盤除外),因?yàn)榇藨?yīng)用程序不會(huì)出現(xiàn)在 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.
推薦答案
除了用戶設(shè)備中已經(jīng)存在的預(yù)定義鍵盤之外,您不能強(qiáng)制用戶輸入.
You can't force the user input through anything other than pre-defined keyboards that already exist in the user's device.
解決此問(wèn)題的唯一方法是編寫自己的自定義動(dòng)態(tài)鍵盤,這是一個(gè)非常糟糕的主意.
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 聲明以編程方式禁用語(yǔ)音輸入.你可以用屬性做到這一點(diǎn):
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.
如果你想以編程方式設(shè)置它,你可以試試這個(gè)::
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 參數(shù)中的值,因此最好的選擇是使用:
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");
看看這里看看你有沒(méi)有可以找到您要查找的內(nèi)容.
Take a look through here and see if you can find what you're looking for.
有關(guān) Google 鍵盤的更多信息 這里 -> 尋找方法 setOptions
More info about Google Keyboard here -> look for method setOptions
這篇關(guān)于以編程方式在android中的軟輸入鍵盤上禁用語(yǔ)音到文本按鈕(麥克風(fēng))的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!