我有一个用于在 Listview 上搜索的 Edittext。
我已将 imeOption
设置为“IME_ACTION_SEARCH”,这样软键盘就会显示搜索键。
问题是,当我点击键盘上的搜索键时,如果 edittext 中没有文本,搜索键会更改为“完成”,而不是关闭键盘。
如果 Edittext 中包含一些文本,则搜索键可以正常工作。
最佳答案
在您的 XML 布局文件中您可以设置
<EditText android:imeOptions="actionSearch" />
或者在您的 Java 源文件中您可以这样做
yourTextField.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
然后您可以覆盖搜索事件的监听器。
yourTextField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
//if textfield value is empty then close keyboard.
//else call your search function.
}
}
});
关于android - ImeAction Search 在点击后更改为 Done,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18894877/