Just started listening in the onconfigurationchanged, the result found that this method will be called when the configuration change is changed, such as the change of the config file, such as screen switch, Android reload the configuration file. Keyboard shadowing does not trigger the method.
Later, the following method is used to solve the keyboard hidden monitoring event.
The outermost layout of the activity
Finalview Activityrootview = Findviewbyid (r.id.activityroot);
Set a listener on the layout to listen for changes to its layouts
Activityrootview.getviewtreeobserver (). Addongloballayoutlistener (Newongloballayoutlistener () {
@Override
Publicvoid Ongloballayout () {
Compare the activity root layout with the current layout size
int heightdiff = Activityrootview.getrootview (). GetHeight ()-activityrootview.getheight ();
In fact, this heightdiff replaced by DP more reliable
if (Heightdiff >100) {
When the size exceeds 100, the virtual keyboard event is typically displayed
}else{
When the size is less than 100, the virtual keyboard or virtual keyboard is hidden
}
}
});
1, method One (if the input method is displayed on the window, then hide, or vice versa)
- Inputmethodmanager IMM = (inputmethodmanager) getsystemservice (Context.input_method_service);
- Imm.togglesoftinput (0, inputmethodmanager.hide_not_always);
2, Method Two (view is to accept the soft keyboard input views, show_forced means force display)
- Inputmethodmanager IMM = (inputmethodmanager) getsystemservice (Context.input_method_service);
- Imm.showsoftinput (view,inputmethodmanager.show_forced); Display keyboard
- Imm.hidesoftinputfromwindow (View.getwindowtoken (), 0); //Force hide keyboard
4 getting the Input method open state
- Inputmethodmanager IMM = (inputmethodmanager) getsystemservice (Context.input_method_service);
- Boolean isopen=imm.isactive (); //isopen returns True to indicate that the input method is open
Android Monitor virtual keyboard hide and show events