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, 2022 in Others by Rahul
• 9,690 points
10,778 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, 2022 by Aditya
• 7,680 points
Worked. Thank you sir for sharing your knowledge
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, 2022 by Soham
• 9,730 points

Related Questions In Others

0 votes
1 answer

How do you calculate the Quintile for groups of rows in Excel?

Use this formula: =MAX(1,ROUNDUP(10*PERCENTRANK($C:$C,$C2,4),0)) To divide into whichever many ...READ MORE

answered Oct 17, 2022 in Others by narikkadan
• 86,360 points
2,194 views
0 votes
1 answer

How do you populate a google sheets/excel column with cells from a column in another sheet in the same document?

You have two options on chronology: sheet-by-sheet =QUERY({Sheet1!X:Z; Sheet2!X:Z; ...READ MORE

answered Dec 19, 2022 in Others by narikkadan
• 86,360 points
2,315 views
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, 2022 in Others by Rahul
• 9,690 points
1,698 views
0 votes
0 answers
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, 2022 in Blockchain by Soham
• 9,730 points
1,578 views
0 votes
0 answers

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

.I can able to change the font ...READ MORE

Jun 22, 2022 in Others by nisha
• 2,210 points
1,000 views
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, 2022 in Others by nisha
• 2,210 points
875 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, 2022 in Others by Aditya
• 7,680 points
1,373 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, 2022 in Others by Aditya
• 7,680 points
2,061 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP