How to hide keybord on Android Studio

To hide the keyboard in Android Studio using Kotlin, you can follow these steps:

Step 1: Get a reference to the current activity's window by calling the window property.

Step 2: Use the setSoftInputMode method to configure the soft input mode for the window. This method takes two parameters, type and flags.

Step 3: Set the type parameter to WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN. This state ensures that the keyboard is always hidden when the activity starts.

Step 4: Set the flags parameter to WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON. This flag ensures that the screen remains on while the activity is visible, even if the keyboard is hidden.

Here's an example of how you can implement these steps in code:

import android.view.WindowManager

// ...

// Get a reference to the current activity's window
val window = activity.window

// Configure the soft input mode for the window
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)

By following these steps, you can hide the keyboard in Android Studio using Kotlin.