Some important constants mean:
HIDE_IMPLICIT_ONLY constant Value: 1 (0x00000001)
A flag in Hidesoftinputfromwindow (ibinder, int) that indicates that the window is hidden if the user does not explicitly display the soft-keyboard window.
HIDE_NOT_ALWAYS constant Value: 2 (0x00000002)
A flag in Hidesoftinputfromwindow (ibinder, int) that indicates that the Soft keyboard window is always hidden, unless it starts with a show_forced display.
Result_hidden constant Value: 3 (0x00000003)
Showsoftinput (View, int, resultreceiver) and Hidesoftinputfromwindow (ibinder, int, resultreceiver) Resultreceiver result code flag: The soft keyboard window transitions from display to hidden state.
RESULT_SHOWN constant Value: 2 (0x00000002)
Showsoftinput (View, int, resultreceiver) and Hidesoftinputfromwindow (ibinder, int, resultreceiver) Resultreceiver result code flag: Soft Keyboard window switches from hidden to displayed state.
RESULT_UNCHANGED_HIDDEN constant Value: 1 (0x00000001)
Showsoftinput (View, int, resultreceiver) and Hidesoftinputfromwindow (ibinder, int, resultreceiver) Resultreceiver result code flag: The soft keyboard window remains hidden when it is not changed.
RESULT_UNCHANGED_SHOWN constant Value: 0 (0x00000000)
Showsoftinput (View, int, resultreceiver) and Hidesoftinputfromwindow (ibinder, int, resultreceiver) Resultreceiver result code flag: The soft keyboard window remains in the state when it is displayed.
SHOW_FORCED constant Value: 2 (0x00000002)
The Showsoftinput (View, int) flag, which means that the user forces the input method to open (such as long press the menu key) and remains open until it is explicitly closed.
SHOW_IMPLICIT constant Value: 1 (0x00000001)
The Showsoftinput (View, int) flag, which indicates that an input window is implicitly displayed, is not directly required by the user. The window may not be displayed.
How Android calls Show and hide system default IME
1. Call the display system default Input method
Method One,
Inputmethodmanager IMM = (inputmethodmanager) getsystemservice (Context.input_method_service); Imm.showSoftInput (m_ Receiverview (view), which accepts a soft keyboard input, inputmethodmanager.show_forced (provides a marker for the current action, show_forced indicates mandatory display));
Method Two,
Inputmethodmanager m= (Inputmethodmanager) Getsystemservice (Context.input_method_service); M.toggleSoftInput (0, Inputmethodmanager.hide_not_always); (This method can implement the input method to switch the display on the window, if the input method is already displayed on the window, then hide, if hidden, then display the input method to the window)
2. Call the hidden system default Input method
((Inputmethodmanager) Getsystemservice (Input_method_service)). Hidesoftinputfromwindow ( WidgetSearchActivity.this.getCurrentFocus (). Getwindowtoken (), inputmethodmanager.hide_not_always); (Widgetsearchactivity is the current activity)
3. Get the Input Method open state
Inputmethodmanager IMM = (inputmethodmanager) getsystemservice (Context.input_method_service); Boolean isOpen= Imm.isactive (); IsOpen returns True indicates that the input method is open
1.//Hide Soft keyboard
((Inputmethodmanager) Getsystemservice (Input_method_service)). Hidesoftinputfromwindow ( WidgetSearchActivity.this.getCurrentFocus (). Getwindowtoken (), inputmethodmanager.hide_not_always);
2,//display soft keyboard, control ID can be Edittext,textview
3, does not automatically eject the keyboard:
With the EditText control, the first display will automatically get focus, and pop up the keyboard, if you do not want to automatically eject the keyboard, there are two ways:
Method One: In the Mainfest file, the corresponding activity settings
Android:windowsoftinputmode= "Statehidden" or android:windowsoftinputmode= "stateunchanged".
Method Two: You can put a hidden textview in the layout, and then Requsetfocus in the OnCreate.
Note TextView do not set visiable=gone, otherwise it will fail
, you can put a hidden textview in the layout, and then Requsetfocus in the OnCreate.
The difference between the two methods:
Displays the soft keyboard area of the input method so that the user can see the Input Method window and can interact with it. Can only be called by the currently active input method, due to token authentication
Showsoftinputfrominputmethod (IBinder token, int flags)
This method toggles the window display of the IME. If the input window is already displayed, it is hidden. If no input window is displayed.
public void Togglesoftinputfromwindow (IBinder windowtoken, int showflags, int hideflags)
Soft keyboard control under special circumstances
Soft keyboard is called in nested child activity in 1.TabActivity:
Show Soft keyboard
Mreasonet.requestfocus (); Inputmethodmanager IMM = (inputmethodmanager) this.getsystemservice (Context.INPUT_METHOD_ SERVICE); Imm.showsoftinput (mreasonet, 0);
Hide Soft Keyboard
Mreasonet.requestfocus (); Inputmethodmanager IMM = (inputmethodmanager) this.getsystemservice (Context.INPUT_METHOD_ SERVICE); Imm.hidesoftinputfrominputmethod (Mreasonet.getwindowtoken (), 0);
Call the soft keyboard in tabactivity, the default will push the bottom tab menu, resulting in interface display and operation is not convenient, you can set the activity properties, so that the keyboard directly cover the bottom tab menu, as follows:
Write android:windowsoftinputmode= "Adjustpan" in this activity in the Androidmainfest.xml file
2. The edittext call soft keyboard in the custom dialog:
Show Soft keyboard
Mydialog.getwindow (). Setsoftinputmode (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
Hide Soft Keyboard
Mydialog.getwindow (). Setsoftinputmode (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
3. Capture screen Click events, Hide IME
GetWindow (). Getdecorview (). Setontouchlistener (New Ontouchlistener () {@Overridepublic Boolean onTouch (View V, Motionevent event) { //TODO auto-generated Method Stub ((Inputmethodmanager) Getsystemservice (input_method_ SERVICE) . Hidesoftinputfromwindow (V.getwindowtoken (), inputmethodmanager.hide_not_always); return false; }});
Android Soft Keyboard