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

How to Fix: Android - Programmatically Hide/Show Soft Keyboard

Hide/Show Android Soft Keyboard Programmatically

Quick Answer: Use the View.OnFocusChangeListener to hide the keyboard when a view loses focus, and show it when a view gains focus.

To programmatically hide or show the Android soft keyboard, you can use the following methods. The first method involves using the getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) method to hide the keyboard. However, this method only works when the activity is paused.

⚠️ Common Causes

  • When using EditText views, the keyboard is shown automatically when focus is gained.

✅ Best Solutions to Fix It

Method 1: Hide Soft Keyboard

  1. Step 1: Get the current focusable view.
  2. Step 2: Check if the focused view is an EditText or a TextField. If it's an EditText, hide the keyboard using getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN).

Method 2: Show Soft Keyboard

  1. Step 1: Get the current focusable view.
  2. Step 2: If the focused view is an EditText, show the keyboard using getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE).

🎯 Final Words

When using ListActivity, you can use the focusable attribute to control the visibility of the keyboard.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions