1

I have a EditView. When some one clicks on the EditView, the only way the keywbaord will go away is if the back button id press.

I saw some apps have it so when the keyboard comes up, there is a button that says done in the lower right hand corner. When this is press the keyboard goes away. My app does not do this, does anybody know how they did this?

Also is it possible to have the keyboard go away when the enter key is press, insrad of having it add another line of text?

Ted pottel
  • 6,869
  • 21
  • 75
  • 134

1 Answers1

0

You can either use TextView.setImeOptions() and pass it actionDone or use the android:imeOptions="actionDone" attribute in your layout.

To close when enter is pressed, use a custom OnEditorActionListener. However, it would probably be better to change the enter key to done as above so as to convey what action will occur.

See this SO question.

Community
  • 1
  • 1
Jeff
  • 820
  • 9
  • 18
  • Hi,Thank you for taking the time to answer my quastion, I was going around in circles trying to figure it out. – Ted pottel Aug 04 '12 at 23:41
  • Hi,How can I " it would probably be better to change the enter key to done as above so as to convey what action will occur."?? also thank you for your info. – Ted pottel Aug 06 '12 at 20:48
  • I was simply saying that it would be better to change the enter key to done rather than having the enter key close the keyboard. By changing the key to done, you convey to the user what will happen when they click that button. – Jeff Aug 06 '12 at 23:13
  • I tried to use the XML version, but it didn't work. I also have `android:inputType="textMultiLine"` in my `EditText`, so not sure if that matters. But adding the `android:imeOptions="actionDone"` doesn't do anything to my return key, and my return key creates new paragraphs, like before. :( Actually I tried to remove the `input` but it didn't make any difference. – Azurespot Jan 01 '15 at 07:04
  • Figured it out! You MUST also put `inputType="text"` or else the keyboard will not respond. I added that and my return key turned into a `Done` key. Thanks to http://stackoverflow.com/questions/1489852/android-handle-enter-in-an-edittext. – Azurespot Jan 01 '15 at 07:23
  • For clarity, the `xml` code to add is `android:imeOptions="actionDone"`. Plus `android:inputType="text"`, as stated above. – Azurespot Jan 01 '15 at 07:26