我遇到了editText.setImeActionLabel
选项的问题。它在premarshmallow设备上运行良好,但不适用于棉花糖。
这是我的参考代码,
edt_testIMEIoptions.setImeOptions(EditorInfo.IME_ACTION_DONE);
edt_testIMEIoptions.setImeActionLabel("Login", EditorInfo.IME_ACTION_DONE);
edt_testIMEIoptions.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
Toast.makeText(TestActivity.this, "Done called", Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});
还尝试了打击选项,
EditorInfo.IME_ACTION_GO
EditorInfo.IME_ACTION_DONE
EditorInfo.IME_ACTION_NEXT
请指导我一个人。
答案 0 :(得分:1)
经过大量的试验和错误后,最终解决方案为我工作。 设置在XMl中的字段下面,
android:singleLine="true"
android:imeOptions="actionDone"
主要类中的代码,
etPassword.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
/*
after entering the password, When user clicks on done button,
keyboard gets hide and clear the focus from the password edittext
*/
if (event != null && event.getAction() != KeyEvent.ACTION_DOWN) {
return false;
} else if (actionId == EditorInfo.IME_ACTION_DONE
|| event == null
|| event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
etPassword.clearFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(etPassword.getWindowToken(), 0);
// Your code
return true;
}
return false;
}
});
希望它能帮助别人。