Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way in Android to get the height of virtual keyboard of device

Tags:

android

sdk

Is there any way in Android to get the height of the virtual keyboard displayed on the device in run time? Actually I want to show a text box above the keyboard.

like image 554
Zeeshan Mirza Avatar asked May 28 '13 09:05

Zeeshan Mirza


People also ask

How do I change the keyboard height on Android?

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.

How do I know what height my keyboard is fluttering?

To know about the keyboard height, you can just check for the bottom property of viewInsets , when the keyboard is onscreen, this will hold the height of keyboard else zero. Note: The bottom property may have value even if some other system ui obscures the flutter ui from bottom. Hope that helps!

How do I change the keyboard size on my Android tablet?

Tap the Gear icon that appears at the top of the Android keyboard. Open Preferences. Tap the Keyboard Height option. You'll see seven different options ranging from "Extra-short" to "Extra-tall." The default is "Normal." Tap the option you prefer.


2 Answers

To solve this I have written a keyboardHeightProvider which can calculate the height of a floating soft keyboard. The Activity can be set to adjustNone or adjustPan in the AndroidManifest.xml.

https://github.com/siebeprojects/samples-keyboardheight

Siebe

like image 59
Siebe Brouwer Avatar answered Sep 19 '22 08:09

Siebe Brouwer


I tried many suggested methods for this, but none seemed to work for Android SDL. I think this is either because the SDL display is "full screen" or that it sits within an "AbsoluteLayout" and therefore the height of the "View" never actually changes. This method worked for me:

Getting the dimensions of the soft keyboard

Window mRootWindow = getWindow(); View mRootView = mRootWindow.getDecorView().findViewById(android.R.id.content); mRootView.getViewTreeObserver().addOnGlobalLayoutListener(     new ViewTreeObserver.OnGlobalLayoutListener() {     public void onGlobalLayout(){         Rect r = new Rect();         View view = mRootWindow.getDecorView();         view.getWindowVisibleDisplayFrame(r);         // r.left, r.top, r.right, r.bottom     }     }); 
like image 31
Dave Lawrence Avatar answered Sep 17 '22 08:09

Dave Lawrence