I use the scene: when the Input method display press the return key, if there is popupwindow first hide Popupwidow.
There are several steps to achieve this:
One, custom edittext:
public class Inputmethodedittext extends edittext{
Private Popujar mpopup;//Custom Popupwindow control
Public Popujar Getmpopup () {
return mpopup;
}
public void Setmpopup (Popujar mpopup) {
This.mpopup = Mpopup;
}
Public Inputmethodedittext (Context context) {
Super (context);
}
Public Inputmethodedittext (context context, AttributeSet Attrs) {
Super (context, attrs);
}
Public Inputmethodedittext (context context, AttributeSet attrs,
int Defstyle) {
Super (context, attrs, Defstyle);
}
@Override
public boolean Dispatchkeyeventpreime (KeyEvent event) {
if (event.getkeycode () = = Keyevent.keycode_back && Mpopup! = null && mpopup.isshow ()) {
This first intercepts the return key before the input method and hides my Popupwindow control
Mpopup.dismiss ();
return true;
}
Return Super.dispatchkeyeventpreime (event);
}
}
Second, the main control code: Messageinput = (inputmethodedittext) Findviewbyid (r.id.chat_content);
Messageinput.setmpopup (MPOPU);
The following code binds the input method to the current custom edittext.
Mimm = (Inputmethodmanager)
Messageinput.getcontext (). Getsystemservice (Context.input_method_service);
After the above two steps can be implemented in the input method before intercepting the Android back key, small remember backup.
Intercept the return key before the IME in Android