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.
By default, the soft keyboard may not appear on the emulator. If you want to test with the soft keyboard, be sure to open up the Android Virtual Device Manager ( Tools => Android => AVD Manager ) and uncheck "Enable Keyboard Input" for your emulator. Now restart the emulator.
The soft keyboard (also called the onscreen keyboard) is the main input method on Android devices, and almost every Android developer needs to work with this component at some point.
RELATED: How to Change the Keyboard on Your Android Phone From there, press the gear icon to open the app's Settings. Next, go to “Preferences.” In the “Layout” section, select “Keyboard Height.” There are a bunch of different heights to choose from.
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.
Rect r = new Rect(); View rootview = this.getWindow().getDecorView(); // this = activity rootview.getWindowVisibleDisplayFrame(r);
Result of this is the amount of space your application uses on screen (works even when activity is not resized). Obviously remaining screen space will be used by the keyboard ( if its visible)
Found id up here: https://github.com/freshplanet/ANE-KeyboardSize/blob/master/android/src/com/freshplanet/ane/KeyboardSize/getKeyboardY.java
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With