Rudy_TM Rudy_TM - 2 years ago 239
Android Question

Getting the dimensions of the soft keyboard

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 in screen in the part of Android or the part of Cocos, it does not matter.

I know that Keyboard has a getHeight() method but I don't want to create new keyboards, i want to use the default one.

Answer Source

We did it with this

myLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

                public void onGlobalLayout() {
                    // TODO Auto-generated method stub
                    Rect r = new Rect();

                    int screenHeight = parent.getRootView().getHeight();
                    int heightDifference = screenHeight - (r.bottom -;
                    Log.d("Keyboard Size", "Size: " + heightDifference);

                    //boolean visible = heightDiff > screenHeight / 3;

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download