List of usage examples for android.app Activity getCurrentFocus
@Nullable
public View getCurrentFocus()
From source file:Main.java
/** * Helper to hide the keyboard/*from w w w. j av a 2s. com*/ * * @param act */ public static void hideKeyboard(Activity act) { if (act != null && act.getCurrentFocus() != null) { InputMethodManager inputMethodManager = (InputMethodManager) act .getSystemService(Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(act.getCurrentFocus().getWindowToken(), 0); } }
From source file:Main.java
public static void hideSoftInput(Activity activity) { View currentFocus = activity.getCurrentFocus(); if (currentFocus != null) { IBinder windowToken = currentFocus.getWindowToken(); if (windowToken != null) { InputMethodManager manager = (InputMethodManager) (activity .getSystemService(Context.INPUT_METHOD_SERVICE)); if (manager != null) { manager.hideSoftInputFromWindow(windowToken, InputMethodManager.HIDE_NOT_ALWAYS); }// w ww .j a v a 2 s . com } } }
From source file:Main.java
/** * Helper Method to hide the keyboard/*ww w .j av a 2 s.c o m*/ */ public static void hideKeyboard(Activity activity) { View view = activity.getCurrentFocus(); if (view != null) { ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } }
From source file:Main.java
public static boolean showSoftInput(Activity activity) { View view = activity.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager) view.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); return imm.showSoftInput(view, InputMethodManager.SHOW_FORCED); }/* ww w . ja v a 2 s. c o m*/ return false; }
From source file:Main.java
public static void hideSoftInput(Activity activity) { View view = activity.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); }/* ww w. ja va 2 s .c o m*/ }
From source file:Main.java
public static void minimizeKeyboard(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); }/* w w w.j ava 2 s . c o m*/ }
From source file:Main.java
public static void hideKeyboard(Activity activity) { // hide keyboard if it's open View view = activity.getCurrentFocus(); if (view != null) { InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); }/*www .j a va2 s . co m*/ }
From source file:Main.java
public static void hideSoftKeyboard(View view) { if (view == null) return;/*from w w w . jav a 2 s . c om*/ View mFocusView = view; Context context = view.getContext(); if (context != null && context instanceof Activity) { Activity activity = ((Activity) context); mFocusView = activity.getCurrentFocus(); } if (mFocusView == null) return; mFocusView.clearFocus(); InputMethodManager manager = (InputMethodManager) mFocusView.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); manager.hideSoftInputFromWindow(mFocusView.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); }
From source file:Main.java
public static void hidePanelAndKeyboard(View panelLayout) { final Activity activity = (Activity) panelLayout.getContext(); final View focusView = activity.getCurrentFocus(); if (focusView != null) { hideKeyboard(activity.getCurrentFocus()); focusView.clearFocus();/*from w w w. java 2 s . com*/ } panelLayout.setVisibility(View.GONE); }
From source file:Main.java
/** * <pre>/*w w w .j av a2 s .c o m*/ * Hide keyboard. * </pre> */ public static void hideKeyboard() { Activity activity = (Activity) getCurrentContext(); View currentFocusedView = activity.getCurrentFocus(); if (currentFocusedView != null) { InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(currentFocusedView.getWindowToken(), 0); } }