问题
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