Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
ViewCompat.setOnApplyWindowInsetsListener don't call when the keyboard appears,on api 29
private fun setUiWindowInsets() {
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { _, insets ->
prevPosition = (binding.rvComments.layoutManager as LinearLayoutManager).findLastVisibleItemPosition()
binding.container.updateLayoutParams<ViewGroup.MarginLayoutParams> {
currentBottomMargin = insets.getInsets(WindowInsetsCompat.Type.ime()).bottom
updateMargins(
bottom = currentBottomMargin
binding.rvComments.scrollToPosition(prevPosition)
insets
I try use WindowCompat.setDecorFitsSystemWindows(window, false)
I call this function in OnViewCreated.My root element is constraint.
What worked for me was setting the listener on the decorView of the window as explained here:
https://stackoverflow.com/a/76163728/1441731
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.