iOS has been used to know that the input method on iOS will automatically turn off the input box, then on Android how to monitor the Input method pop-up and shutdown it? This article provides you with a reliable way to achieve this.
Demo Effect Video Address
First, configure in Androidmanifest
Android:windowsoftinputmode= "Adjustresize"
This way, every time the input method pops up and closes, the height is recalculated to achieve the effect of putting the layout on top
Then we're going to customize a layout that listens for layout size changes
public class Checksoftinputlayout extends Framelayout {private Onresizelistener Monresi
Zelistener; Public Checksoftinputlayout {Super (context);} public Checksoftinputlayout AttributeSet attrs) {Super (context, attires);} public Checksoftinputlayout (context context, AttributeSet attrs, int def STYLEATTR) {Super (context, attrs, defstyleattr); @TargetApi (in) public checksoftinputlayout AttributeSet attrs, int defstyleattr, int defstyleres) {Super (context, Attrs, defstyleattr, defstyleres); @Override Pro tected void onsizechanged (int w, int h, int oldw, int oldh) {super.onsizechanged (W, H, OLDW, old); if (Monresizelistener
!= null) {monresizelistener.onresize (W, H, OLDW, old);} public void Setonresizelistener (Onresizelistener listener) {This.monresizelistener = listener;} public Interface Onresi
Zelistener {void onResize (int w, int h, int oldw, int old);}
Then put the custom layout of the above into the activity you need, and then bind the listener event
Mrootlayout.setonresizelistener (this);
@Override public
void onResize (int w, int h, int oldw, int oldh) {
//If first initialized if
(OLDH = = 0) {
return;
//If the user screens convert if
(w!= oldw) {return
;
}
if (H < OLDH) {
//IME popup
} else if (H > Oldh) {
//IME close
setcommentviewenabled (false, false);
}
int distance = H-old;
Eventbus.getdefault (). Post (new Inputmethodchangeevent (Distance,mcurrentimageid));
This way, as long as the input method pop-up and shutdown can automatically monitor, to turn off the input box effect, so as the Apple experience is very consistent. This is the end of the introduction, if there is any good ideas, but also welcome comments to share the point of praise! [Github Demo address] (Https://github.com/gupengcheng/CheckSoftInputDemo)