@Override Public voidOnresume () {Super. Onresume (); //gets the height of the current screen contentGetWindow (). Getdecorview (). Addonlayoutchangelistener (NewView.onlayoutchangelistener () {@Override Public voidOnlayoutchange (View V,intLeftintTopintRightintBottomintOldLeft,intOldTop,intOldRight,intOldbottom) { //get the bottom of the view visible areaRect rect =NewRect (); GetWindow (). Getdecorview (). Getwindowvisibledisplayframe (rect); //Avoid recurring eventsString keyboardstatus = String.Format ("%d%d%d", Bottom,oldbottom,rect.bottom); if(Keyboardstatus.equals (lastkeyboardstatus)) {return; } lastkeyboardstatus=Keyboardstatus; if(bottom!=0 && oldbottom!=0 && bottom-rect.bottom <= 0) {HashMap<String,Object> data =NewHashmap<string, object>(); Data.put ("EventName", "Hide"); Imutils.dispatch ("KeyboardEvent", data); }Else{HashMap<String,Object> data =NewHashmap<string, object>(); Data.put ("EventName", "show"); Data.put ("Height", bottom-rect.bottom); Imutils.dispatch ("KeyboardEvent", data); } } }); }
Android listens for soft keyboard events and gets the keyboard height