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
window.insetsController?.controlWindowInsetsAnimation( | |
WindowInsets.Type.ime(), | |
-1, | |
null, | |
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
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar"> | |
<!-- Rest of the theme attributes... --> | |
<item name="android:navigationBarColor">@android:color/transparent</item> | |
</style> |
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
// You have to wait for the view to be attached to the | |
// window (otherwise, windowInsetController will be null) | |
view.doOnLayout { | |
view.windowInsetsController?.show(WindowInsets.Type.ime()) | |
// You can also access it from Window | |
window.insetsController?.show(WindowInsets.Type.ime()) | |
} |
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
// New way of requesting the app to be laid out fullscreen | |
// (for example, when implementing edge-to-edge) | |
window.setDecorFitsSystemWindows(false) |
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
// Old way (now deprecated) of requesting the app to be | |
// laid out fullscreen and hiding the navigation | |
view.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or | |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or | |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
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
view.setOnApplyWindowInsetsListener { view, windowInsets -> | |
val systemWindowInsets = windowInsets.getInsets(WindowInsets.Type.systemBars()) | |
// It's also possible to use multiple types | |
val insets = windowInsets.getInsets( | |
WindowInsets.Type.ime() or | |
WindowInsets.Type.systemGestures() | |
) | |
windowInsets | |
} |
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
scrollView.viewTreeObserver.addOnScrollChangedListener { | |
animationController?.setInsetsAndAlpha(Insets.of(0, 0, 0, scrollView.scrollY), 1f, 0f) | |
} |
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
val listener = object : WindowInsetsAnimationControlListener { | |
override fun onCancelled() { | |
animationController = null | |
} | |
override fun onReady(controller: WindowInsetsAnimationController, types: Int) { | |
animationController = controller | |
} | |
} |
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
val inputLayoutMarginBottom = inputLayout.marginBottom | |
val callback = object : WindowInsetsAnimation.Callback(DISPATCH_MODE_STOP) { | |
override fun onProgress(insets: WindowInsets, animations: MutableList<WindowInsetsAnimation>): WindowInsets { | |
inputLayout.updateLayoutParams<ViewGroup.MarginLayoutParams> { | |
updateMargins(bottom = inputLayoutMarginBottom + | |
insets.getInsets(WindowInsets.Type.ime()).bottom) | |
} | |
return insets | |
} | |
} |
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
val imeInsets = view.rootWindowInsets.getInsets(WindowInsets.Type.ime()) | |
if (imeInsets.isVisible()) { | |
// Move view by the height of the IME | |
view.translationX = imeInsets.bottom | |
} |
NewerOlder