自定义键盘候选视图导致 Gmail EditText 跳转

Custom Keyboard Candidates View is causing Gmail EditText to jump

当我使用自定义键盘在 Gmail 应用程序中输入文本时,每次击键屏幕都会 'jump' 上下移动。

我已经找到了 Candidates View 的原因(因为当它被禁用或高度为零时屏幕不会跳转)。 Android 文档状态 '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.' 所以我怀疑 'jump' 可能是由 Gmail 视图平移引起的。

有谁知道如何防止这种 'jump' 发生,因为它使键盘很难使用?

我检查过没有调用 setCandidatesViewShown(false) 并且自定义候选视图的 onMeasure 方法总是返回正确的高度。

一个完美的解决方案在这里。 只需在 InputMethodService 中覆盖以下方法,

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

希望对您有所帮助。