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

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 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

Android: how to make keyboard enter button say “Search” and handle its click?

In the layout set your input method options to search. <EditText android:imeOptions=”actionSearch” android:inputType=”text” /> In the java add the editor action listener. editText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { performSearch(); return true; } return false; } });

How to show soft-keyboard when edittext is focused

To force the soft keyboard to appear, you can use EditText yourEditText= (EditText) findViewById(R.id.yourEditText); yourEditText.requestFocus(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT); And for removing the focus on EditText, sadly you need to have a dummy View to grab focus. To close it you can use InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0); This works … Read more

tech