How to hide soft keyboard on android after clicking outside EditText?

The following snippet simply hides the keyboard: public static void hideSoftKeyboard(Activity activity) { InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService( Activity.INPUT_METHOD_SERVICE); if(inputMethodManager.isAcceptingText()){ inputMethodManager.hideSoftInputFromWindow( activity.getCurrentFocus().getWindowToken(), 0 ); } } You can put this up in a utility class, or if you are defining it within an activity, avoid the activity parameter, or call hideSoftKeyboard(this). The trickiest part is … Read more

How do I detect if software keyboard is visible on Android Device or not?

This works for me. Maybe this is always the best way for all versions. It would be effective to make a property of keyboard visibility and observe this changes delayed because the onGlobalLayout method calls many times. Also it is good to check the device rotation and windowSoftInputMode is not adjustNothing. boolean isKeyboardShowing = false; … Read more

How to capture the “virtual keyboard show/hide” event in Android?

2020 Update This is now possible: On Android 11, you can do view.setWindowInsetsAnimationCallback(object : WindowInsetsAnimation.Callback { override fun onEnd(animation: WindowInsetsAnimation) { super.onEnd(animation) val showingKeyboard = view.rootWindowInsets.isVisible(WindowInsets.Type.ime()) // now use the boolean for something } }) You can also listen to the animation of showing/hiding the keyboard and do a corresponding transition. I recommend reading Android … Read more

Android How to adjust layout in Full Screen Mode when softkeyboard is visible

Based on yghm’s workaround, I coded up a convenience class that allows me to solve the problem with a one-liner (after adding the new class to my source code of course). The one-liner is: AndroidBug5497Workaround.assistActivity(this); And the implementation class is: public class AndroidBug5497Workaround { // For more information, see https://issuetracker.google.com/issues/36911528 // To use this class, … Read more

Create Passcode view in Android

To capture the backspace,its actually the delete key in android. you can capture it via editText.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_DEL){ //delete key pressed } return false; } }); To hide the keyboard try this InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);