0

keyboard hide keyboard show

just like the picture, when the keyboard is show ,it hide the logo.

the question is how to listen the keyboard show/hide even? have some sample?

cs x
  • 571
  • 1
  • 7
  • 22

2 Answers2

0

add this attribute to your activity in manifest

 android:windowSoftInputMode="adjustResize"
Bajirao Shinde
  • 1,374
  • 1
  • 18
  • 25
0

Get a reference to the layout which you want to hide when keyboard pops up. You can set the visibility of that to GONE when keyboard is shown and to VISIBLE otherwise. So your task now is to detect whether the keyboard is shown or hidden. For that you can use ViewTreeObserver.OnGlobalLayoutListener().

rootView = getWindow().getDecorView().getRootView();
        rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                Rect rect = new Rect();
                rootView.getWindowVisibleDisplayFrame(rect);

                int screenHeight = rootView.getHeight();
                int keyboardHeight = screenHeight - (rect.bottom - rect.top);
                if(keyboardHeight > screenHeight / 3){
                    //hide the layout
                }
                else{
                    //show the layout
                }
            }
        });
aravindkanna
  • 623
  • 1
  • 7
  • 22