Getting the dimensions of the soft keyboard

后端 未结 11 763
故里飘歌
故里飘歌 2020-11-27 14:56

Is there a way to know the size of the keyboard that is shown in the screen?

I am using Cocos2dx for programming, but I want to know the height of the keyboard shown

11条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 15:17

    We did it with this

    myLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
    
                    @Override
                    public void onGlobalLayout() {
    
                        Rect r = new Rect();
                        parent.getWindowVisibleDisplayFrame(r);
    
                        int screenHeight = parent.getRootView().getHeight();
                        int heightDifference = screenHeight - (r.bottom - r.top);
                        Log.d("Keyboard Size", "Size: " + heightDifference);
    
                    }
                });
    

    We only resize views with the keyboard, so we could use this.

提交回复
热议问题