Created
August 3, 2022 19:31
-
-
Save indrih17/c5766c8f6957a7ab4f8e9cefdb90840f to your computer and use it in GitHub Desktop.
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
/** Compat версия метода [View.getWindowInsetsController]. */ | |
fun View.windowInsetsControllerCompat(): WindowInsetsControllerCompat? = | |
ViewCompat.getWindowInsetsController(this) | |
/** Показать клавиатуру и установить фокус на [view]. */ | |
fun showKeyboard(view: EditText): Boolean = | |
view.windowInsetsControllerCompat()?.let { controller -> | |
view.requestFocus() | |
view.post { controller.show(WindowInsetsCompat.Type.ime()) } | |
} != null | |
/** Скрыть клавиатуру и если [view] имеет фокус, то убрать его. */ | |
fun hideKeyboard(view: View): Boolean = | |
view.windowInsetsControllerCompat()?.let { controller -> | |
if (view.hasFocus()) view.clearFocus() | |
controller.hide(WindowInsetsCompat.Type.ime()) | |
} != null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment