Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

android hide keyboard

public void hideKeyboard(Context context, View view) {
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.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));
Comment

android hide soft keyboard

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

// call from inside an Activity / Fragment
hideKeyboard(view);
Comment

android hide soft keyboard

// Available on Android API 30+ / AndroidX Core 1.5+
public void hideKeyboard(View view) {
  ViewCompat.getWindowInsetsController(this)
            .hide(WindowInsetsCompat.Type.ime());
}

// @see https://youtu.be/acC7SR1EXsI
// @see https://developer.android.com/reference/androidx/core/view/ViewCompat#getWindowInsetsController(android.view.View)
// @see https://developer.android.com/reference/androidx/core/view/WindowInsetsControllerCompat#hide(int)
// @see https://developer.android.com/reference/androidx/core/view/WindowInsetsCompat.Type#ime()
Comment

hide keyboard android

//With AndroidX:
fun View.hideKeyboard() = ViewCompat.getWindowInsetsController(this)
    ?.hide(WindowInsetsCompat.Type.ime())
Comment

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);
}

Comment

PREVIOUS NEXT
Code Example
Java :: sieve of eratosthenes java 
Java :: java timestamp 
Java :: java ip regex pattern 
Java :: stream distinct by property 
Java :: java create txt file 
Java :: jframe add label java 
Java :: java selenium wait 
Java :: collision java 
Java :: find the greatest number in hashmap 
Java :: java fps 
Java :: java split string into list 
Java :: find difference in days between two dates java 
Java :: java how to get elapsedTime 
Java :: convert base64 to bitmap android 
Java :: java remove first element from array 
Java :: Xlint:deprecation android studio 
Java :: java unique id 
Java :: java ldaps certificate self signed 
Java :: change date jdatepicker java 
Java :: execute application jar 
Java :: decimal format 
Java :: java write string 
Java :: how to create javafx project in eclipse 
Java :: Spring Boot Hibernate remove underscore naming strategy 
Java :: java take out cn from dn 
Java :: java max from 3 parameters 
Java :: install java 11 jdk raspberry pi 
Java :: how to stop timer in java 
Java :: how to set landscape in android studio 
Java :: Duplicate class org.intellij.lang.annotations. 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =