samples-keyboardheight icon indicating copy to clipboard operation
samples-keyboardheight copied to clipboard

fit more divices with modify the KeyboardHeightProvider handleOnGlobalLayout methods

Open kingyisong opened this issue 4 years ago • 2 comments

when i test this code in the xiaomi devices,i find the height is not accurate。in some case,the activity window size is too larger include the top status bar,in other case, the window visible display frame is too larger include the botom navigate bar。so i chang the code like this,not use the absoulte screen height,rather than use the relative height,save the first bottom,then calculate the change when the keboard pop up

private void handleOnGlobalLayout() {

    Point screenSize = new Point();
    activity.getWindowManager().getDefaultDisplay().getSize(screenSize);

    Rect rect = new Rect();
    popupView.getWindowVisibleDisplayFrame(rect);

    // REMIND, you may like to change this using the fullscreen size of the phone
    // and also using the status bar and navigation bar heights of the phone to calculate
    // the keyboard height. But this worked fine on a Nexus.
    int orientation = getScreenOrientation();


    if (lastY == 0) {
        lastY = rect.bottom;
    }

    int keyboardHeight = lastY - rect.bottom;

    if (keyboardHeight == 0) {
        notifyKeyboardHeightChanged(0, orientation);
    }
    else if (orientation == Configuration.ORIENTATION_PORTRAIT) {
        this.keyboardPortraitHeight = keyboardHeight; 
        notifyKeyboardHeightChanged(keyboardPortraitHeight, orientation);
    } 
    else {
        this.keyboardLandscapeHeight = keyboardHeight; 
        notifyKeyboardHeightChanged(keyboardLandscapeHeight, orientation);
    }
}

kingyisong avatar Dec 02 '20 02:12 kingyisong

thanks so much for the snippet. I was having trouble with android 10 devices with default code

Jack29913 avatar Jan 18 '21 11:01 Jack29913

thanks, it worked

vanthien113 avatar Jul 27 '22 15:07 vanthien113