user8 user8 - 1 year ago 143
Android Question

How to add custom InputMethodService to Activity?

I decided to create a custom keyboard for my application. I know that this is not the best idea, since it's hurting the user friendliness, that's why I will just make it optional in Preferences.

After having it all done in a class

public class CustomKeyboard extends InputMethodService implements KeyboardView.OnKeyboardActionListener
. I struggle to add it as a
. I tried with the
but I get incompatible types when casting it.

I found that I can get it w/o the Service but it is highly unrecommended and I would need a whole new implementation.

Ideally, I would use it for the EditText command line in the app. So a direct binding to it would also do the job.

After hiding the system input method, how to make this input service the default one?


P.S. If there is an obvious easy way to do this, I am sorry, but I just made the transition to Android and I am still learning.

Answer Source

how to make this input service the default one?

You don't. Input methods are for the entire device, not a single EditText. Hence, the user needs to opt into using your input method. Quoting the documentation:

After installing the desired IMEs, a user can select which one to use from the system settings, and use it across the entire system; only one IME may be enabled at a time.