0

help,Android question:I hava to listen soft keyboard's state changed event ,but I could'nt find some api to use ?So , asking for help here,thanks..

Lynn
  • 1
  • 2
  • WHat soft keyboard changed event? Unless you can describe it better, my answer is "it doesn't exist". If you mean the soft keyboard being opened- it doesn't exist. – Gabe Sechan Mar 03 '16 at 04:40

1 Answers1

0

You can use this function:

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);
}
Akbar
  • 430
  • 4
  • 18