希望我按下软键盘右下角回车直接进入下一步
1.首先改变软键盘右下角样式为 完成 (有的手机的完成是√的样式,还有的是回车标志,而有的时候无法更改还会是换行的标志)
对于这一个样式属性一般有以下几种
actionNone : 回车键,按下后光标到下一行
actionGo : Go,
actionSearch : 放大镜
actionSend : Send
actionNext : Next
actionDone : Done,确定/完成,隐藏软键盘,即使不是最后一个文本输入框
根据不同的情况进行选择
<EditText
android:id="@+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:imeOptions="actionSearch"/>
2.重写方法
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
//声明一个软键盘对象
if (actionId == EditorInfo.IME_ACTION_DONE) {
//如果按下了软键盘的回车建
if (inputMethodManager.isActive()) {
inputMethodManager.hideSoftInputFromWindow(view.getApplicationWindowToken(), 0);
}
//判断虚拟键盘是否打开,若打开则关闭软键盘
//接下来可以任意发挥
}