Developing a Custom Keyboard (Input Method Editor) for Android
Input Method Editor (IME) on Android is a service registered in the system via InputMethodService. Unlike iOS, Android gives developers much more freedom: IME can occupy arbitrary height, contain WebView, work in background via bound service. This freedom comes with its own set of pitfalls.
InputMethodService Lifecycle
The keyboard exists as a system service. Key callbacks:
-
onCreateInputView()— create keyboard view, called once -
onStartInputView(EditorInfo, Boolean)— each time keyboard appears; readEditorInfo.inputTypeto understand field type—password, email, numbers, arbitrary text -
onFinishInputView(Boolean)— field lost focus -
onComputeInsets(Insets)— critical for managing spacing
EditorInfo.inputType is a bit mask. Password field: inputType & InputType.TYPE_MASK_VARIATION == InputType.TYPE_TEXT_VARIATION_PASSWORD. Ignore this and autocorrect suggests in password fields—guaranteed Play Store rejection.
Height and Insets Problem
Most common complaint: keyboard covers EditText. Reason: wrong onComputeInsets implementation. By default, the system doesn't know what screen portion IME occupies and doesn't shift content.
@Override
public void onComputeInsets(InputMethodService.Insets outInsets) {
super.onComputeInsets(outInsets);
outInsets.contentTopInsets = outInsets.visibleTopInsets;
}
This only works if host app uses adjustResize or adjustPan in windowSoftInputMode. With adjustNothing nothing helps—it's host responsibility. Document this.
Passing Text to Field
Insert character: getCurrentInputConnection().commitText("a", 1). Delete: getCurrentInputConnection().deleteSurroundingText(1, 0). Composing text (for IMEs with intermediate state like Japanese/Chinese): setComposingText() + finishComposingText().
InputConnection can be null—happens on focus loss between calls. Check every call:
val ic = currentInputConnection ?: return
ic.commitText(text, 1)
Data Storage and Permissions
IME is a privileged component, but permissions work standard. For internet access need INTERNET in manifest. Dictionary and settings—SharedPreferences or Room. Predictive input server-side—only with explicit user consent plus Privacy Policy description.
Play Store checks IMEs with doubled attention: hidden keystroke transmission—direct policy violation. If keyboard sends anything to server (layout analytics, predictive input), declare it via Data Safety Form.
Theme and Material Design
Starting Android 12, keyboard should support Dynamic Color from Material You. MaterialTheme via AppCompatDelegate + DynamicColors.applyToActivitiesIfAvailable() doesn't work in IME directly—apply theme to inputView explicitly via ContextThemeWrapper.
Jetpack Compose inside IME works from Compose 1.2, but needs careful setup: ComposeView inside onCreateInputView() with explicit setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnDetachedFromWindow).
Testing
Test on real devices with different versions: Android 8 (API 26) minimum if not using new IME API. Test in Chrome for Android (separate InputConnection), Gmail, inputType=numberPassword fields. Simulator works but insets behavior differs.
Timeline: 1–3 weeks depending on predictive input, multi-language support, custom theming. Cost calculated individually.







