Getting the dimensions of the soft keyboard

get keyboard height android java
how to adjust layout when soft keyboard appear in android
android edittext soft keyboard listener
pixel 3 keyboard size
xamarin forms get keyboard height
visible keyboard
keyboard hide event android

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.

We did it with this

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

                public void onGlobalLayout() {

                    Rect r = new Rect();

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


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

Android Designing: Get the height of soft keyboard of device, That depends of the keyboard app. Swiftkey, for example, allows the size adjustement of the keyboard in landscape mode. Using a PopupWindow, you can have separate "keyboard behaviour" for it, and it will notify you what the size of the keyboard is. The PopupWindow has the height of the screen, but 0px width, so you won't see it, it won't affect your activity, but will provide you with the information you need.

Rect r = new Rect();
View rootview = this.getWindow().getDecorView(); // this = activity

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:

Reduce the size of soft keyboard on edit text click, (When the keyboard is closed, the dimensions of the softKeyboardRect rectangle addChild( textField ); //track soft keyboard and stage resize events textField. This adjustment of the VISUAL DISPLAY FRAME can be very well used to find out the height of the keyboard as : (when the soft keyboard is open) SOFT_KEYBOARD_HEIGHT = ROOT_VIEW_HEIGHT - (VISUAL_DISPLAY_FRAME_HEIGHT + EXTRA_SCREEN_HEIGHT) The code to achieve the above is :

if your activity is not fullscreen, using code below:

            new ViewTreeObserver.OnGlobalLayoutListener() {

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

                        int screenHeight = content.getRootView()
                        int heightDifference = screenHeight
                                - (r.bottom -;
                        int resourceId = getResources()
                                        "dimen", "android");
                        if (resourceId > 0) {
                            heightDifference -= getResources()
                        if (heightDifference > 100) {
                            keyBoardHeight = heightDifference;

                        Log.d("Keyboard Size", "Size: " + heightDifference);
                    // boolean visible = heightDiff > screenHeight / 3;

Adobe Flash Platform * Handling application display changes, Air Native Extension to measure soft keyboard size (Android). This is an Air //​get the height of the keyboard var keyboardHeight:Number = MeasureKeyboard. Xamarin: Get the keyboard height Cross platform I wish to write a dependency service to get the keyboard height when the keyboard appears after tapping any entry

If you want to calculate the Virtual Keyboard height while your activity does not change in size (adjustPan) then you can use this sample:

It uses a hidden window in order to calculate the height difference between the window and the root view of the activity.

freshplanet/ANE-KeyboardSize: Air Native Extension , Working with a soft keyboard on Android can be confusing. Finding the correct view size was easy - all views get notified about a size change via the  To open the On-Screen Keyboard. Swipe in from the right edge of the screen, and then tap Search. (If you're using a mouse, point to the lower-right corner of the screen, move the mouse pointer up, and then click Search.) Enter On-Screen Keyboard in the search box, and then tap or click On-Screen Keyboard.

You can't tell. No, really: you simply can't tell.

The keyboard does not need to be any particular shape. It does not have to be placed at the bottom of the screen (many of the most popular options are not), it does not have to keep its current size when you change text fields (almost none do depending on the flags). It does not even have to be rectangular. It may also just take over the entire screen.

Keyboard Handling on Android, Buy Celluon EPIC Ultra-Portable Full-Size Virtual Keyboard: Keyboards After getting use to it he loves it, he just projects it onto a brown wood grain finished  UWP refers to the Soft Keyboard as an Input Pane. By default UWP does an AdjustPan, the same as Android, with no scroll capability. In order to do a resize, I put together this code in your MainPage.cs

Celluon EPIC Ultra-Portable Full-Size Virtual Keyboard, The Android system shows an on-screen keyboard—known as a soft input method—when a text field in your UI receives focus. To provide the  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. See these screenshots for a visual reference.

Handle keyboard input, Additionally, machine learning has also been applied [4] towards equipping the virtual keyboards with the capability to adjust the key size and 

Effective virtual keyboard design with size and space adaptation , The Android system shows an on-screen keyboard, known as a soft input method​, when a text field in your UI receives focus. To provide the best user 

  • check out…
  • Do you want keyboard then cocos2d-x has already incorporated the android keyBoard you may check in the Test Classes -> TextInput where they are using android keyboard in cocos2d-x ... check if it may help you
  • @Rudy_TM : Got things you needed ??? ...
  • No :/ we can not get the height of the keyboard, the problem is that we want to push up textfield if they are behind the keyboard. we put a constant 'activity.getCurrentFocus().getMeasuredHeight()' when the keyboard is called and multiply it with the number of rows of the keyboard keys, in the smartphones it works, but in the tablets, it does not work, so that is not the solution :/ but meanwhile we will be using this u.u
  • Is the height difference in px or dp?
  • It's in pixels, because height measurements return pixel quantities.
  • It won't work if there is more than keyboard shown on the screen, i.e. system buttons (back, home, etc)
  • For me (Nexus 7 with Android 5.0) it does take into account system buttons.
  • Which display components cover in react-top or rect-bottom?
  • Are you sure that keyboard is visible at that point in time? I experienced some issues with that and I had to get dimensions when activity layout was updated.
  • Thanks for this simplest and useful answer! Will this work with phones which use on-screen system buttons such as LGs? And you don't have any issues with this solution so far?
  • Yep, I used nexus 4 when I was developing a game, thus I had to deal with on-screen buttons. Project is on-hold, but I still installed it on Z5 to give it a go - still worked fine on Android 6
  • thank you, status_bar_height is very very important if you want to translate editview by Y
  • do you have find a solution or is android just not capable to provide real apps? i mean, being super dynamic in one sense but not providing to handle the dynamic
  • and sorry for not adding it as a comment, because I simply couldn't.