ImeAction Search is changed to Done after tapping on it

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-22 08:11:52

问题


I have an Edittext for searching on Listview.

I have set imeOption to 'IME_ACTION_SEARCH' so that soft-keyboard will show search key on it.

The problem is that when I tap on search key on keyboard if edittext contains no text in it, the search key changes to 'Done' instead of dismissing the keyboard.

If the Edittext contains some text in it the search key works well.


回答1:


In your XML layout file you can set

<EditText android:imeOptions="actionSearch" />

Or in your Java source file you could do

yourTextField.setImeOptions(EditorInfo.IME_ACTION_SEARCH);

Then you can override the listener for the search event.

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.
        }
    }
});



回答2:


you should do this to your edittext in xml

     android:imeOptions="actionSearch|actionSearch"

this will show you search button always!




回答3:


I found the problem behind this. It was happening because the OnEditorAction Listener was not properly set on Edittext. Since listener was not properly set call was not reaching onEditorAction() method.



来源:https://stackoverflow.com/questions/18894877/imeaction-search-is-changed-to-done-after-tapping-on-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!