Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android hide keyboard on btn click [duplicate]

I want to hide keyboard on click event of a button. Any help would be appreciated

like image 785
user2041902 Avatar asked Mar 15 '13 08:03

user2041902


People also ask

How do I stop my keyboard from clicking on the button?

To hide keyboard, use the following code. InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); inputMethodManager. hideSoftInputFromWindow(v. getApplicationWindowToken(),0);

How do I hide the soft keyboard on Android after clicking outside EditText Kotlin?

This example demonstrates how to hide a soft keyboard on android after clicking outside EditText using Kotlin. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.


2 Answers

to hide the virtual keyboard:

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editView.getWindowToken(), 0);
like image 152
Nermeen Avatar answered Oct 07 '22 00:10

Nermeen


InputMethodManager inputManager = (InputMethodManager)
                                  getSystemService(Context.INPUT_METHOD_SERVICE); 

inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
                                     InputMethodManager.HIDE_NOT_ALWAYS);

I put this right after the onClick(View v) event. You need to import android.view.inputmethod.InputMethodManager;

The keyboard hides when you click the button.

like image 45
KDeogharkar Avatar answered Oct 06 '22 23:10

KDeogharkar