[英]Weird issue with Samsung keyboard on Android with Libgdx
在我的游戏中,当触摸文本字段时,视图会随着键盘向上移动。
这是 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")
}
上面的代码获取键盘高度和状态发送到我的 libgdx 游戏 class 以便相机向上/向下移动屏幕。
使用普通键盘,它会在显示键盘时发送类似这样的内容:
当键盘被隐藏时:
但是在键盘 ID 为“com.samsung.android.honeyboard/.service.HoneyBoardService”的三星设备上,当键盘显示一次时,它会执行所有这些操作:
这使得键盘阻塞了我游戏中的文本字段,因为视图没有向上移动。
我的 gdxVersion 是 1.11.0
我怎样才能解决这个问题?
您好,这不是 libGDX 问题。 你需要为你的活动提供参数,特别说明你想要这个值是什么(是屏幕键盘而不是硬件键盘)
android:windowSoftInputMode
如此处所述https://developer.android.com/guide/topics/manifest/activity-element.html#wsoft并考虑您想要的参数
adjustResize
adjustPan
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.