EditText软键盘(IME)收起监听

2018-03-14  本文已影响0人  全汪汪

参考文章:

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

而下面为收起软键盘代码

上一篇 下一篇

猜你喜欢

热点阅读