关于 edittext 软键盘退出监听解决方法
关于 edittext 软键盘退出监听解决办法edittext 有个onCreateInputConnection 的方法,通过它可以自定义一
关于 edittext 软键盘退出监听解决办法
edittext 有个onCreateInputConnection 的方法,通过它可以自定义一个输入法连接器,那里连接器里面有个方法(finishComposingText)能监听输入完成的动作原文参考自站长网:http://www.software8.co/wzjs/yidongkaifa/3313.html.
Java代码
- public class MyEditText extends EditText{
-
- public MyEditText(Context context) {
- super(context);
- }
- private OnFinishComposingListener mFinishComposingListener;
-
- public void setOnFinishComposingListener(OnFinishComposingListener listener){
- this.mFinishComposingListener =listener;
- }
- @Override
- public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
- return new MyInputConnection(super.onCreateInputConnection(outAttrs), false);
- }
- public class MyInputConnection extends InputConnectionWrapper {
- public MyInputConnection(InputConnection target, boolean mutable) {
- super(target, mutable);
- }
- @Override
- public boolean finishComposingText() {
- boolean finishComposing = super.finishComposingText();
- if(mFinishComposingListener != null){
- mFinishComposingListener.finishComposing();
- }
- return finishComposing;
- }
- }
- public interface OnFinishComposingListener{
- public void finishComposing();
- }
- }