您的位置:首页 > 移动开发 > Android开发

Android 监听软键盘按键与改变软键盘右下角按键样式

2017-01-09 17:42 417 查看
android:singleline=”true”

android:imeoptions=”actionSearch”

一定要加singleline=”true”!!!

actionNone : 回车键,按下后光标到下一行

actionGo : Go,

actionSearch : 放大镜

actionSend : Send

actionNext : Next

actionDone : Done,确定/完成,隐藏软键盘,即使不是最后一个文本输入框

xml

<EditText
android:imeOptions="actionSend"
android:id="@+id/et_input_message"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginRight="15dp"
android:background="#ffffff"
android:layout_weight="1"
android:singleLine="true"
/>


java

et_input_message.setOnEditorActionListener(new EditText.OnEditorActionListener(){

@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
LogUtil.d("zza",actionId+"==");
switch (actionId) {
case EditorInfo.IME_ACTION_NONE:
Toast.makeText(getApplicationContext(), "点击NONE", Toast.LENGTH_SHORT).show();
break;
case EditorInfo.IME_ACTION_GO:
Toast.makeText(getApplicationContext(), "点击GO", Toast.LENGTH_SHORT).show();
break;
case EditorInfo.IME_ACTION_SEARCH:
Toast.makeText(getApplicationContext(), "点击SEARCH", Toast.LENGTH_SHORT).show();
break;
case EditorInfo.IME_ACTION_SEND:
Toast.makeText(getApplicationContext(), "点击SEND", Toast.LENGTH_SHORT).show();
break;
case EditorInfo.IME_ACTION_NEXT:
Toast.makeText(getApplicationContext(), "点击NEXT", Toast.LENGTH_SHORT).show();
break;
default:
break;
}
return false;
}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android 软键盘