我使用单行编辑文本,因此当我单击编辑文本框时,我会得到“Go”而不是 Enter 按钮。但我想要 Enter 键代替“Go”键。我该怎么做..请有人能给出解决方案吗?
我不确定,但你可以尝试
android:imeOptions="actionDone"
,总之你需要尝试android:imeOptions
属性。
EditText editText = findViewById(R.id.editText); // Your EditText
Button button = findViewById(R.id.button); // Your Button
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
button.performClick(); // Imitation of pressing the button
// Hide the keyboard after pressing
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
return true;
}
return false;
}
});