显示“完成”软键盘上的键
在我的应用程序中将文本输入到 EditText 时,我需要软键盘来显示“完成”键。在 Android 2.1 设备上会显示“完成”按钮,但在 2.3 或更高版本上不会显示。
这是我使用的代码:
e.setImeOptions(EditorInfo.IME_ACTION_DONE);
e.setOnEditorActionListener(
new EditText.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId,KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH ||
actionId == EditorInfo.IME_ACTION_DONE ||
event.getAction() == KeyEvent.ACTION_DOWN &&
event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
Toast.makeText(getBaseContext(), e.getText().toString(), Toast.LENGTH_SHORT).show();
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(e.getWindowToken(), 0);
return true;
}
return false;
}
});
我使用的是 Android 版本 2.3.4 的三星设备。
编辑文本的屏幕截图:
I need the softkeyboard to display the 'Done' key when inputting text into an EditText in my application. On an Android 2.1 device the 'Done' button is displayed, but not on 2.3 or it higher.
This is the code I use:
e.setImeOptions(EditorInfo.IME_ACTION_DONE);
e.setOnEditorActionListener(
new EditText.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId,KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH ||
actionId == EditorInfo.IME_ACTION_DONE ||
event.getAction() == KeyEvent.ACTION_DOWN &&
event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
Toast.makeText(getBaseContext(), e.getText().toString(), Toast.LENGTH_SHORT).show();
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(e.getWindowToken(), 0);
return true;
}
return false;
}
});
I am using a samsung device with Android version 2.3.4.
Screenshort of the edittext:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是 Android 版本的问题,而是您设备使用的 IME 的问题。三星(我认为还有一些 HTC)IME 永远不会将字母更改为“Done”或“Next”或“Go”。
It is not Android version's fault, but the IME your device use. Samsung (and some of HTC, I think) IME never change the letter to "Done" or "Next" or "Go".