Search code examples
javaandroidkeyboardime

Custom Keyboard Candidates View is causing Gmail EditText to jump


When I enter text using my custom keyboard into the Gmail app the screen will 'jump' up and down with each key stroke.

I've tracked down the cause to the Candidates View (as when this is disabled or has a height of zero the screen doesn't jump). The Android docs state 'Note that because the candidate view tends to be shown and hidden a lot, it does not impact the application UI in the same way as the soft input view: it will never cause application windows to resize, only cause them to be panned if needed for the user to see the current focus.' So I suspect the 'jump' might be caused by the Gmail view panning.

Does anyone know how to prevent this 'jump' from happening as it makes the keyboard very difficult to use?

I've checked that setCandidatesViewShown(false) isn't being called and the onMeasure method for the custom Candidate view is always returning the correct height.


Solution

  • A perfect solution is here. Just override the following method in the InputMethodService,

    @Override
    public void onComputeInsets(InputMethodService.Insets outInsets) {
        super.onComputeInsets(outInsets);
        if (!isFullscreenMode()) {
            outInsets.contentTopInsets = outInsets.visibleTopInsets;
        }
    }
    

    Hope it help.