Created
December 23, 2020 11:20
-
-
Save xvadsan/04ed19eba0444613816a02a28da1de8e to your computer and use it in GitHub Desktop.
keyboard listener
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private var mLastContentHeight by Delegates.notNull<Int>() | |
private val keyboardLayoutListener = OnGlobalLayoutListener { | |
val currentContentHeight: Int = requireActivity().window.findViewById<View>(Window.ID_ANDROID_CONTENT).getHeight() | |
if (mLastContentHeight > currentContentHeight + 100) { | |
showKeyboard() | |
mLastContentHeight = currentContentHeight | |
} else if (currentContentHeight > mLastContentHeight + 100) { | |
hideKeyboard() | |
mLastContentHeight = currentContentHeight | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun initKeyboardListener() { | |
mLastContentHeight = requireActivity().window.findViewById<View>(Window.ID_ANDROID_CONTENT).height | |
requireActivity().getRootView().viewTreeObserver.addOnGlobalLayoutListener(keyboardLayoutListener) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
requireActivity().getRootView().viewTreeObserver.removeOnGlobalLayoutListener(keyboardLayoutListener) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment