“Android menyembunyikan keyboard” Kode Jawaban

Android menyembunyikan keyboard lunak

// 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()
Merlin4 (personal)

Android menyembunyikan 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));
Merlin4 (ranken)

Android menyembunyikan keyboard lunak

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);
Merlin4 (personal)

Sembunyikan Keyboard Android

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

Cara menyembunyikan keybord di android

  
fun hideKeybord() {
            val view = this.currentFocus
            if (view != null) {
                val hideKey = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
                hideKey.hideSoftInputFromWindow(view.windowToken, 0)
            } else {
                window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
            }
        }

// Call your function whatever you want

	hideKeybord() 
an-jorge

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

Dizzy Dugong

Jawaban yang mirip dengan “Android menyembunyikan keyboard”

Pertanyaan yang mirip dengan “Android menyembunyikan keyboard”

Lebih banyak jawaban terkait untuk “Android menyembunyikan keyboard” di Java

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya