Cocos2dxEditBox.java

private void registKeyboardVisible() {
            getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    Rect r = new Rect();
                    getWindowVisibleDisplayFrame(r);
                    int heightDiff = getRootView().getHeight() - (r.bottom - r.top);
                    // if more than a quarter of the screen, its probably a keyboard
                    if (heightDiff > mScreenHeight/4) {
                        if ( Cocos2dxEditText.this.mTopMargin == 0 ) {
                            Cocos2dxEditText.this.setTopMargin(r.bottom);
                        }
                        if (!keyboardVisible) {
                            keyboardVisible = true;
                        }
                    } else {
                        if (keyboardVisible) {
                            keyboardVisible = false;
                            Cocos2dxEditBox.this.hide();
                        }
                    }
                }
            });
        }
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐