Last active
April 3, 2018 09:11
-
-
Save liminal/5a4bb1fce48efa38e41d to your computer and use it in GitHub Desktop.
Utility for hiding android keyboard #android
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
import android.app.Activity; | |
import android.content.Context; | |
import android.view.View; | |
import android.view.WindowManager; | |
import android.view.inputmethod.InputMethodManager; | |
public class KeyboardUtil { | |
public static void hideKeyboard(final Context ctx, final View view) { | |
InputMethodManager imm = (InputMethodManager)ctx.getSystemService(Context.INPUT_METHOD_SERVICE); | |
if (view != null) { | |
imm.hideSoftInputFromWindow(view.getWindowToken(), 0); | |
} else { | |
if (ctx instanceof Activity) { | |
((Activity)ctx).getWindow().setSoftInputMode( | |
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment