Skip to content

Instantly share code, notes, and snippets.

@JChudasama
Created August 11, 2015 16:31
Show Gist options
  • Save JChudasama/d32f6160b41ade8991ee to your computer and use it in GitHub Desktop.
Save JChudasama/d32f6160b41ade8991ee to your computer and use it in GitHub Desktop.
public class KeyboardUtility
{
public static void hideSoftKeyboard(Activity activity)
{
try
{
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void showSoftKeyboard(Activity activity)
{
try
{
InputMethodManager inputMethodManager = (InputMethodManager)activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), InputMethodManager.SHOW_FORCED, 0);
}
catch (Exception e)
{
// TODO: handle exception
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment