spiegel-keyman/android/docs/engine/KMManager/applyKeyboardHeight.md
Matthew Lee 6be82ac9b8 Adding Docs for getKeyboardHeightMin/max & updating webview height
Handling invalid orientations

updating orientation logic

refresh webview height if ApplyKeyboardHeight() has been applied without KB active

I ran into a bug building this code into app-builders and fixed it downstream. This commit pushes it upstream.

While resize dialog is open:
- Keyboard WebView is NOT loaded (isKeyboardLoaded() == false)
- ACTION_UP saves to SharedPreferences:  Works
 -But skips WebView layout update:  Because keyboard not loaded
 - User exits dialog, keyboard appears:
    - If the keyboard WebView loads and reads from SharedPreferences properly:  Works
    - But if there's a timing issue or the WebView had old layout params cached:  Touch zone mismatch
2025-11-21 14:50:03 -06:00

3 KiB

title
KMManager.applyKeyboardHeight()

Summary

The applyKeyboardHeight() method sets the height of the keyboard frame for the device's current screen orientation (portrait vs landscape) or a specified orientation.

Syntax

KMManager.applyKeyboardHeight(Context context, int height)

or

KMManager.applyKeyboardHeight(Context context, int height, int orientation)

Parameters

context
The context
height
The height of the keyboard frame in density-independent pixels (dp). Pass KMManager.KeyboardHeight_Reset to reset the keyboard height (for the current orientation) to device-specific defaults.
orientation (Optional)
Accepts a screen orientation value. This is most useful if you want to change the size of the keyboard in the other (non-current) orientation. If orientation is not defined, keyboard height is set for the current device orientation.

Description

Use this method when you want to increase or decrease the keyboard height for the device in the current screen orientation. This height is independent from the height of the suggestion banner frame.

For reference, here's a table of the default Keyman keyboard heights for various devices and screen orientation.

Device Type Default height (dp)
Portrait
Default height (dp)
Landscape
Default handset (160dpi) 205 120
High Density handset (240dpi) 170 100
Extra High Density handset (320dpi) 270 140
Extra Extra Extra
High Density handset (640 dpi)
270 140
7" tablet 305 200
10" tablet 405 280

Note: This new keyboard height would be applied for all platforms, so an adjusted keyboard height for a phone would appear too small for a tablet.

Examples

Example: Using applyKeyboardHeight()

The following script illustrates the use of applyKeyboardHeight():

    // Increase the Keyman keyboard height (default Keyman value for most phones is 205dp)
    int newKeyboardHeight = 300;
    KMManager.applyKeyboardHeight(this, newKeyboardHeight);

or

    import android.content.res.Configuration;
    ...
    // Increase the Keyman keyboard height for landscape mode to 250dp (default Keyman value for most phones is 100dp)
    int newKeyboardHeight = 250;
    KMManager.applyKeyboardHeight(this, newKeyboardHeight, Configuration.ORIENTATION_LANDSCAPE);

The following script illustrates the use of applyKeyboardHeight() to reset keyboard height to default:

    // Reset keyboard to default height
    KMManager.applyKeyboardHeight(this, KMManager.KeyboardHeight_Reset);

See also