List of usage examples for android.app Activity getCurrentFocus
@Nullable
public View getCurrentFocus()
From source file:Main.java
public static void hideSoftKeyBoard(Activity activity) { final View v = activity.getWindow().peekDecorView(); if (v != null && v.getWindowToken() != null) { try {/*from ww w.j a v a2 s . c o m*/ ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } catch (Exception e) { e.printStackTrace(); } } }
From source file:com.joeyturczak.jtscanner.utils.Utility.java
/** * Hides the keyboard/* ww w. j a v a2s . c o m*/ * Credit: http://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard */ public static void hideKeyboard(Activity activity) { // Check if no view has focus: View view = activity.getCurrentFocus(); if (view != null) { InputMethodManager inputManager = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } }
From source file:Main.java
public static void hideSoftInputView(Activity activity) { if (activity.getWindow() .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { InputMethodManager manager = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); View currentFocus = activity.getCurrentFocus(); if (currentFocus != null) { manager.hideSoftInputFromWindow(currentFocus.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); }//from w ww .jav a 2 s .co m } }
From source file:com.app.opencity.activities.MainActivity.java
public static void hideKeyboard(Activity activity) { InputMethodManager inputMethodManager = (InputMethodManager) activity .getSystemService(Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0); }
From source file:nth.com.ares.utils.Utils.java
public static void hideSoftKeyboard(Activity activity) { try {//w w w .jav a2 s. c o m InputMethodManager inputMethodManager = (InputMethodManager) activity .getSystemService(Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0); } catch (Exception e) { // e.printStackTrace(); } // try { // InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); // inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0); // } catch (Exception e) { //// e.printStackTrace(); // } }
From source file:com.vinexs.tool.Utility.java
public static void hideKeyBroad(Activity activity) { try {/* www. j a v a 2s. c o m*/ View currentView = activity.getCurrentFocus(); if (currentView == null) { throw new Exception("Cannot get current focus"); } InputMethodManager inputMethodManager = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(currentView.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } catch (Exception ignored) { } }
From source file:com.app.sample.chatting.widget.KJChatKeyboard.java
/** * /*from w ww. jav a 2 s .co m*/ */ public static void showKeyboard(Context context) { Activity activity = (Activity) context; if (activity != null) { InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInputFromInputMethod(activity.getCurrentFocus().getWindowToken(), 0); imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); } }
From source file:fr.cph.chicago.util.Util.java
private static void showSnackBar(@NonNull final Activity activity, final int message) { if (activity.getCurrentFocus() != null) { Snackbar.make(activity.getCurrentFocus(), activity.getString(message), Snackbar.LENGTH_SHORT).show(); } else {/*from w w w .jav a2 s. co m*/ Toast.makeText(activity, activity.getString(message), Toast.LENGTH_LONG).show(); } }
From source file:com.xabber.android.ui.activity.ChatActivity.java
public static void hideKeyboard(Activity activity) { // Check if no view has focus: View view = activity.getCurrentFocus(); if (view != null) { InputMethodManager inputManager = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); }//from ww w . ja v a 2 s. c om }
From source file:com.tlongdev.bktf.util.Utility.java
public static void hideKeyboard(Activity activity) { if (activity == null) { return;//from w w w . j a v a 2 s . c o m } //overkill? View view = activity.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); }