Skip to content

SoftKeyboardStateHelper

Stanislav Koshutsky edited this page Mar 6, 2017 · 1 revision

SoftKeyboardStateHelper is a class which could help you to manage software keyboard, basically to detect if keyboard is shown on screen or being closed. For that purpose you need to implement callback methods of SoftKeyboardStateListener interface:

public interface SoftKeyboardStateListener {
    void onSoftKeyboardOpened(int keyboardHeightInPx);
    void onSoftKeyboardClosed();
}

There are several constructors could be used to instantiate this class. You could send an Activity (or instantiated Fragment - getActivity() will be called) where you want to monitor soft keyboard or View which must be a root view of an Activity.
It has also methods to implicitly hide or show a keyboard.

public static void showKeyboard(final EditText view)  
public static void hideKeyboard(final EditText view) 
public static void hideKeyboard(final EditText... editTexts)  

the last method could be used in case if you not sure which EditText holds focus and has soft keyboard linked to (when a screen has several EditText widgets).

Clone this wiki locally