Created
October 23, 2014 01:34
-
-
Save kioltk/8f611a3ee4d1f7729b87 to your computer and use it in GitHub Desktop.
Hide keyboard easily
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
package com.droidkit.util | |
import android.app.Activity; | |
import android.content.Context; | |
import android.view.View; | |
import android.view.WindowManager; | |
import android.view.inputmethod.InputMethodManager; | |
/** | |
* Created by kiolt_000 on 23/10/2014. | |
*/ | |
public class KeyboardUtil { | |
public static void hide(View probablyFocusedView, Activity activity) { | |
if (probablyFocusedView != null) | |
probablyFocusedView.clearFocus(); | |
if (activity != null) { | |
activity.getWindow().setSoftInputMode( | |
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); | |
View focusedView = activity.getCurrentFocus(); | |
if (focusedView != null) { | |
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); | |
inputMethodManager.hideSoftInputFromWindow(focusedView.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment