How do you close hide the Android soft keyboard programmatically

0 votes
I have an EditText and a Button in my layout and after commencing the  writing in the edit field and clicking on the Button, I want to hide the virtual keyboard when touching outside the keyboard. I assume that this is a simple piece of code, but where can I find an example of it?
Feb 23 in Others by Rahul
• 8,980 points
632 views

2 answers to this question.

0 votes

One solution to hide keyboard would be to use the following lines of code:

InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

Here pass HIDE_IMPLICIT_ONLY at the position of showFlag and 0 at the position of hiddenFlag. It will forcefully close the soft Keyboard.

answered Feb 23 by Aditya
• 7,280 points
0 votes

The solution that I can think of right away in order to hide the keyboard would be by using:-
 

getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN );


This can be used to suppress the soft-keyboard until the user actually touches the editText View.

answered Feb 23 by Soham
• 8,730 points

Related Questions In Others

0 votes
1 answer

How to open the Google Play Store directly from my Android application?

By using developer.andriod.com, one can solve this ...READ MORE

answered Feb 8 in Others by Rahul
• 8,980 points
15 views
0 votes
0 answers

How do I determine the size of my array in C?

How do I determine the size of ...READ MORE

May 1 in Others by Kichu
• 19,040 points
22 views
0 votes
1 answer

How to prepare an APK for the Amazon Android App Store

you should use zipalign during every build, ...READ MORE

answered Jun 1 in Others by nisha
• 2,160 points
22 views
0 votes
1 answer
0 votes
1 answer

Kotlin Convert Bitcoin value into Satoshi Value

java.lang.NumberFormatException: For input string: "45,586" This means ...READ MORE

answered Apr 12 in Blockchain by Soham
• 8,730 points
42 views
0 votes
0 answers
0 votes
0 answers

can the font type of an Edittext,Radio Button and CheckBox be changed in Android

TextView text = (TextView) layout.findViewById(R.id.text); text.setText(msg); Typeface font = ...READ MORE

Jun 22 in Others by nisha
• 2,160 points
12 views
0 votes
1 answer

How do I get the current date and time in PHP?

The time would go by your server ...READ MORE

answered Feb 16 in Others by Aditya
• 7,280 points
26 views
0 votes
1 answer

How do I display an alert dialog on Android?

You could use an AlertDialog for this ...READ MORE

answered Feb 22 in Others by Aditya
• 7,280 points
149 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP