6

I have a pretty simple screen with a couple of EditText widgets and a button. In the emulator, when I click on the EditText widget, a virtual keyboard comes up. However, I can't seem to get rid of it. Clicking on an empty space on the screen does not make it go away. Only clicking the virtual Return key or the hardware Back button makes it disappear.

I don't have a real Android phone handy, so is this an emulator only thing or will it be like this on the actual device. If it is, what can I do to make the virtual keyboard go away, when I click elsewhere on the form?

AngryHacker
  • 54,471
  • 90
  • 289
  • 523

6 Answers6

5

Click the back button. They keyboard is an activity. There's not an easy way to remove the keyboard when clicking on a random area of the screen.

Falmarri
  • 44,586
  • 38
  • 140
  • 186
  • Do android users known in general that this is the way to remove the keyboard? – AngryHacker Dec 29 '10 at 06:51
  • @AngryHacker - "Do android users known in general that this is the way to remove the keyboard?" My HTC Desire has a button/key on the virtual keyboard with a keyboard icon and 'down arrow' which hides it when pressed. I suspect this just does the same as the phone's Back button. – Squonk Dec 29 '10 at 07:33
  • It has to do with focusables. Clicking on a different part of the GUI doesn't necessarily clear the focus from the current widget. If you set your overall layout to be focusable, this might work, but it might also screw up focusing on nested widgets. – Falmarri Dec 29 '10 at 15:46
  • Re "Do android users known in general that this is the way to remove the keyboard?" As an Android user, there is no way I would press the back button - I would fear that this would close the app. Essential that app is smart about this, and closes the keyboard whenever appropriate. – ToolmakerSteve Nov 13 '15 at 01:51
3

AngryHacker , I woud refer you to this post how to close/hide the android soft keyboard.

Hope this helps.

Community
  • 1
  • 1
100rabh
  • 6,028
  • 5
  • 24
  • 40
2

I lived this problem and i resolved it. This problem is about InputMethodManager.SHOW_FORCED value in my project. When i open keypad using SHOW_FORCEDthen when i try to close keypad, keypad was not closing.

For Example :

activity.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(view, InputMethodManager.SHOW_FORCED);

If you use above way to open keypad, you may try to change SHOW_FORCED value with SHOW_IMPLICIT value

For Example :

activity.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
oguzhan
  • 1,503
  • 1
  • 20
  • 20
2

I think in the emulator you can press Escape to hide the keyboard. On a real device there is a hide button on the keyboard or you can press elsewhere in the ui. That's how it works on my HTC Desire S anyway.

Caltor
  • 2,306
  • 23
  • 51
0

I have the Galaxy S2 which is running Andriod 2.3.6.
I was having issues with the keyboard not moving out of the way after entering the needed text when logging into websites. I found that hitting the hardware return button does take the virtual keyboard out of the way. But occassionally it will take the web browser back one page. Which is frustrating because then I have to re-enter the log in info for whatever web site I'm connecting too. Hopefully Android 4.x has solved some of these glitchy issues.

Doug
  • 1
0

You can achieve this by doing the following steps:

  1. Make the parent view(content view of your activity) clickable and focusable by adding the following attributes

        android:clickable="true" 
        android:focusableInTouchMode="true" 
    
  2. Implement a hideKeyboard() method

        public void hideKeyboard(View view) {
            InputMethodManager inputMethodManager =(InputMethodManager)getSystemService(Activity.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
        }
    
  3. Lastly, set the onFocusChangeListener of your edittext.

        edittext.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (!hasFocus) {
                    hideKeyboard(v);
                }
            }
        });
    

Source

Community
  • 1
  • 1
Darpan
  • 5,193
  • 3
  • 45
  • 74