<EditText
android:id=“@+id/met_comment”
android:layout_width=“0dp”
android:layout_weight=“1”
android:hint=“评论两句…”
android:imeOptions=“actionSend”
android:singleLine=“true”
android:layout_height=“wrap_content” />
一定还要设置singLine=“true”,不然回车还是换行的功能
1.actionNext下一步,通常用于跳转到下一个EditText
2.actionGo前往,通常用于打开链接
3.actionSend发送,通常用于发送信息
4.actionSearch搜索,通常用于搜索信息
5.actionDone确认,通常表示事情做完了
metComment.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == event.KEYCODE_ENTER) {
if(!MStringUtils.isNullOrEmpty(metComment.getText().toString()))
{
addEvaluate(metComment.getText().toString());
}else{
MyToast.showMessage(“评论内容不得为空”);
}
}
return false;
}
});
软键盘的关闭软键盘的显示和隐藏的监听
//mllDetailsPost是EditText的父布局
mllDetailsPost.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
mllDetailsPost.getWindowVisibleDisplayFrame®;
int screenHeight = mllDetailsPost.getRootView()
.getHeight();
int heightDifference = screenHeight - (r.bottom);
if (heightDifference > 200) {
//软键盘显示
mllEt.setVisibility(View.GONE);
mtvSend.setVisibilit