Show error message on SearchView

隐身守侯 提交于 2019-12-10 18:15:13

问题


I'm using a SearchView in the ActionBar and I'd like to know if it's possible to show an error if the input is invalid, similar as EditText's showError() method.

I know that this could be anti pattern because any search shouldn't be invalid. I configured the SearchView to react in a way that if it detects that the user put something and that something is similar to anything valid then it will advert it to the user. But for that purpose I'd like to get the same effect as EditText's showError() method, as I said before.

Is this possible or I'll have to conform with showing a Toast or something similar?


回答1:


Try this.

int id = searchView.getContext()
                        .getResources()
                        .getIdentifier("android:id/search_src_text", null, null);
EditText editText = (EditText) searchView.findViewById(id);
editText.setError("Your error message");


来源:https://stackoverflow.com/questions/31440644/show-error-message-on-searchview

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