How do i add words to the suggestions on top of the soft keyboard

允我心安 提交于 2019-12-20 14:43:27

问题


Is there any way to add words to the suggestions in the soft keyboard? For a specific Edittext field i would like to add a list of names to the suggestions that pops up on top of the soft keyboard in android 2.0.

Does anyone know if this is possible?


回答1:


Here is the source code of the soft keyboard. If you go through the code, you will see that it uses a Suggest class which inside has different dictionaries.

If you want to add words for a specific EditText you would need to add and remove or change freq of a certain word from those dictionaries.

Some issues:

  • I couldn't find a way to get the InputMethodService's instance. (If you can, please answer my question here)
  • Android allows developers to program their own InputMethodService. I am working on one myself and my implementation doesn't use that dictionaries. So your feature will not work with my IME.

I would suggest using Auto Complete.




回答2:


You can't add additional words to the ones the IME finds internally, however you can whole-sale supply your own completions via InputMethodManager.displayCompletions():

http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html#displayCompletions(android.view.View, android.view.inputmethod.CompletionInfo[])

This is what the auto complete text view uses to show its completions in the IME, when the IME is full screen so it can't be seen. Note that your app is still responsible for showing the completions itself, so they will be available to the user if the IME is not full screen.

(And sorry about the lack of documentation on that method.)



来源:https://stackoverflow.com/questions/2531253/how-do-i-add-words-to-the-suggestions-on-top-of-the-soft-keyboard

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