Coding⏱️ 2 min read📅 2026-06-03

How to Fix: How can I close/hide the Android soft keyboard programmatically?

Hide Android soft keyboard programmatically by listening for touch events outside the EditText and hiding the keyboard when touched.

Quick Answer: Use the View.OnTouchListener interface to detect touch events outside the EditText, then call the View.setFocusableInTouchMode() method on the parent view to hide the keyboard.

To close or hide the Android soft keyboard programmatically, you can use the requestFocusInWindow method on an EditText field. This method will remove the focus from the current view and any views that have focus and then return focus to the next view in the sequence.

🔧 Proven Troubleshooting Steps

Method 1: Focus on Another View

  1. Step 1: Get a reference to the EditText field.
  2. Step 2: Set focus on another view, such as a Button, using the requestFocus method.

Method 2: Use a Click Listener

  1. Step 1: Set an OnClickListener on the Button. In the listener, get a reference to the EditText field.
  2. Step 2:: Hide the keyboard by calling the requestFocusInWindow method on the EditText field.

✨ Wrapping Up

By following these methods, you can programmatically close or hide the Android soft keyboard when touching outside the keyboard.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions