参考文章:
http://blog.csdn.net/lnn368/article/details/51201148
在TextView类下有一个方法
setOnEditorActionListener(l: OnEditorActionListener)
这监听一般是当IME(软键盘)有输入时会触发
public interface OnEditorActionListener{
boolean onEditorAction(TextView v,int actionId, KeyEvent event);
}
这里主要是帮你所要输入的EditText设置监听,运用actionId在软键盘确认时自动收起
if (actionId == EditorInfo.IME_ACTION_DONE){
val imm = getSystemService(Context.INPUT_METHOD_SERVICE)as InputMethodManager
imm.hideSoftInputFromWindow(currentFocus.applicationWindowToken, InputMethodManager.HIDE_NOT_ALWAYS)
}
其中EditorInfo.IME_ACTION_DONE在软键盘确认时触发的id
而下面为收起软键盘代码
网友评论