1

In my game, when a textfield is touched, the view moves up along with the keyboard.

Here's the code in AndroidLauncher:

onCreate(){
//other codes...
setListenerToRootView()
}

private fun setListenerToRootView() {
    val activityRootView: View = window.decorView.findViewById(content)
    activityRootView.viewTreeObserver.addOnGlobalLayoutListener(keyboardLayoutListener)
}

private var keyboardLayoutListener: OnGlobalLayoutListener? = OnGlobalLayoutListener {
    val visibleDisplayFrame = Rect()
    window.decorView.getWindowVisibleDisplayFrame(visibleDisplayFrame)
    sizeChanged(visibleDisplayFrame.width(), visibleDisplayFrame.height())
}

override fun sizeChanged(width: Int, height: Int) {
    val heightRatio = Gdx.graphics.height / main.worldHeight
    val worldHeightChanged = height / heightRatio
    val keyboardStatus = if (height == Gdx.graphics.height) KeyboardStatus.HIDE else KeyboardStatus.SHOW
    main.platformsObservable.notifyObservers(Triple(ObservableKeys.SCREEN_SIZE_CHANGED, keyboardStatus, worldHeightChanged))
    log.error("SCREEN_SIZE_CHANGED, status = $keyboardStatus")
}

The above code gets the keyboard height and status to send to my libgdx game class for the Camera to move the screen up/down.

With a normal keyboard it would send something like this for when the keyboard is shown:

  • SCREEN_SIZE_CHANGED, status = SHOW

and when the keyboard is hidden:

  • SCREEN_SIZE_CHANGED, status = HIDE

But on Samsung devices with the keyboard id of "com.samsung.android.honeyboard/.service.HoneyBoardService" then it does all this when the keyboard is shown once:

  • SCREEN_SIZE_CHANGED, status = HIDE
  • SCREEN_SIZE_CHANGED, status = SHOW
  • SCREEN_SIZE_CHANGED, status = SHOW
  • SCREEN_SIZE_CHANGED, status = SHOW

And this is making the keyboard blocking the textfield in my game because the view doesn't move up.

My gdxVersion is 1.11.0

How can I fix this?

Jay N
  • 348
  • 3
  • 11

1 Answers1

0

Hi This isn't a libGDX issue. You need to provide parameters to your activity specifically saying what you want for this value (being the screen keyboard as opposed to a hardware one)

android:windowSoftInputMode

as described here https://developer.android.com/guide/topics/manifest/activity-element.html#wsoft and consider what you want for the parameters

adjustResize

adjustPan

londonBadger
  • 611
  • 2
  • 5
  • 5
  • Adding this attribute alone in the manifest doesn't do it for me. Even following this solution: https://stackoverflow.com/questions/21467006/how-to-push-up-the-screen-when-soft-keybord-is-displayed the screen wouldn't be full size. – Jay N Jan 22 '23 at 00:33
  • what about ```android:windowSoftInputMode="adjustNothing"``` – londonBadger Jan 22 '23 at 12:02
  • Am I supposed remove the code that moves the camera up on my libgdx code? Because these android:windowSoftInputMode doesn't seem to be doing anything. – Jay N Jan 22 '23 at 22:35
  • Yes. remove your code you shouldn't need to implementthis on your own because its an activity setting. Try here https://stackoverflow.com/questions/1964789/move-layouts-up-when-soft-keyboard-is-shown which is ```getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);``` – londonBadger Jan 23 '23 at 13:03
  • So I've tried window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) and it doesn't work on any keyboard type for me, regular & samsung. The only thing does anything is the deprecated window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) but this pushes the screen up and makes the screen smaller and have 2 black bars on the side above the keyboard instead of just keep the scale and moving the screen up. For the manifest I've tried a couple settings: adjustResize, adjustNothing, adjustPan – Jay N Jan 23 '23 at 19:12
  • There are some manual workarounds listed here https://stackoverflow.com/questions/7417123/android-how-to-adjust-layout-in-full-screen-mode-when-softkeyboard-is-visible/19494006#19494006 but the activity stuff should work really is it just Samsung? – londonBadger Jan 24 '23 at 16:32