android EditText控键在调用软键盘的时候功能实现:
1、Editext 实现绑定输入法回车键代码实现
password.setOnEditorActionListener(new EditText.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
// TODO Auto-generated method stub
if (actionId == EditorInfo.IME_ACTION_SEND)
{
// 在这里编写自己想要实现的功能
}
}
return false;
}
});
2、Edittext 绑定删除键代码实现与注意
password.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DEL) {
String content = password.getText().toString();
int length = content.length();
content.endsWith("-");
}
return false;
}
});
注意:在绑定删除键的时候,如你重写了
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
return super.dispatchKeyEvent(event);
//return true;
}
这个方法之后,必须返回return super.dispatchKeyEvent(event);,则如返回return true时,绑定的删除键则无效!