帮助,Android问题:我想听软键盘的状态改变事件,但我找不到一些api可以使用?所以,在这里寻求帮助,谢谢......
答案 0 :(得分:0)
您可以使用此功能:
public void setListenerToRootView() {
ViewTreeObserver.OnGlobalLayoutListener globalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int height = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
if (height > 100) {
isKeyboardVisible = true;
keyboardHeight = height;
} else {
isKeyboardVisible = false;
difHeight = height;
}
}
};
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(globalLayoutListener);
}