输入法弹出会导致应用窗口往上移动
InputMethodService.java中有关窗口重置代码
只需要重写onComputeInsets,将outInsets.contentTopInsets 设为decor.getHeight()
@Override
public void onComputeInsets(final InputMethodService.Insets outInsets) {
super.onComputeInsets(outInsets);
//解键盘顶起应用
View decor = getWindow().getWindow().getDecorView();
outInsets.contentTopInsets = decor.getHeight();
}
源码中,关于contentTopInsets的说明:
/**
* Information about where interesting parts of the input method UI appear.
*/
public static final class Insets {
/**
* This is the top part of the UI that is the main content. It is
* used to determine the basic space needed, to resize/pan the
* application behind. It is assumed that this inset does not
* change very much, since any change will cause a full resize/pan
* of the application behind. This value is relative to the top edge
* of the input method window.
*/
public int contentTopInsets;