KeyboardStateEvents
LiveData notification when keyboard opens or closes, plus some handy extension functions.
Getting started
The first step is to include KeyboardStateEvents into your project, for example, as a Gradle compile dependency:
implementation 'com.github.guilhe:keyboard-state-events:${LATEST_VERSION}'
Sample usage
Call bindKeyboardStateEvents()
in you AppCompatActivity
or FragmentActivity
and observe KeyboardLiveData.state
to get notified:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
...
KeyboardLiveData.state.observe(this, Observer {...})
bindKeyboardStateEvents()
}
}
Just that and you're done! ?
Also, some handy extension functions:
ComponentActivity.toggleKeyboard()
ComponentActivity.dismissKeyboard()
ComponentActivity.isKeyboardOpen()
ViewGroup.isKeyboardOpen()