当前位置: 首页 > 工具软件 > EditBox > 使用案例 >

cocoscreator-Editbox安卓输入上顶

宗政子辰
2023-12-01

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();
                        }
                    }
                }
            });
        }
 类似资料: