Why does the virtual keyboard not disappear?

I have a pretty simple screen with several EditText widgets and a button. In the emulator, when I click on the EditText widget, a virtual keyboard appears. However, I cannot get rid of this. Clicking on an empty spot on the screen does not make it leave. Just pressing the virtual back button or the hardware back button makes it disappear.

I don't have a real Android phone, and this is the only emulator, or it will look like a real device. If so, what can I do to make the virtual keyboard disappear when I click elsewhere on the form?

+5
source share
6 answers

AngryHacker, I will refer to this post how to close / hide the soft keyboard Android.

Hope this helps.

+3
source

Click the back button. They are an activity. There is no easy way to remove the keyboard when you click on a random area of ​​the screen.

+3
source

, Escape, . ui. , HTC Desire S .

+2

, . InputMethodManager.SHOW_FORCED . SHOW_FORCED, , , .

:

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

, SHOW_FORCED SHOW_IMPLICIT value

:

activity.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
+1

Galaxy S2, Andriod 2.3.6.
, -. , . - . , -, . , Android 4.x .

0

, :

  • ( ) ,

        android:clickable="true" 
        android:focusableInTouchMode="true" 
    
  • hideKeyboard()

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

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

Source

0
source

All Articles