Answers for "how to hide soft keyboard in android"

4

android hide keyboard

public void hideKeyboard(Context context, View view) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

// call from inside an Activity...
hideKeyboard(this, view);
hideKeyboard(this, getCurrentFocus());
hideKeyboard(this, getWindow().getDecorView());
hideKeyboard(this, findViewById(android.R.id.content));
Posted by: Guest on February-11-2021
1

android hide keyboard

public static void hideKeyboard(Activity activity) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
        //Find the currently focused view, so we can grab the correct window token from it.
        View view = activity.getCurrentFocus();
        //If no view currently has focus, create a new one, just so we can grab a window token from it
        if (view == null) {
            view = new View(activity);
        }
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
Posted by: Guest on October-05-2021
0

How to programmatically hide Android soft keyboard

private void closeSoftKeyboard() 
    { 
    	//If using a fragment use getActivity().getCurrentFocus()
        View v = this.getCurrentFocus(); 
  
  		// If Soft Keyboard is visible, it will be hide
        if (v != null) { 
          //If using a fragment use getActivity().getSystemService(...)
            InputMethodManager inputManager 
                = (InputMethodManager) 
                    getSystemService(Context.INPUT_METHOD_SERVICE); 
            inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0); 
        } 
    }
Posted by: Guest on December-29-2020
0

hide keyboard android

//With AndroidX:
fun View.hideKeyboard() = ViewCompat.getWindowInsetsController(this)
    ?.hide(WindowInsetsCompat.Type.ime())
Posted by: Guest on July-08-2021

Code answers related to "how to hide soft keyboard in android"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language