I want to remove focus and text from SearchView in onResume().
I tried searchView.clearFocus() but it is not working.
Thi
For those who are looking to get rid of the focus when the Activity is started AND the SearchView is in the Menu, I did these 3 things, it might work with just a few:
1.- Create a parent class of SearchView. Let's call it RafaSearchView:
class RafaSearchView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0)
: SearchView(context, attrs, defStyleAttr) {
init {
setIconifiedByDefault(false)
}
}
2.- Get the xml where you have your Toolbar, and set touchable="false" and focusableInTouchMode="true":
3.- On onCreateOptionsMenu(Menu) when I'm declaring my RafaSearchView, call:
searchView?.isIconified = false
searchView?.clearFocus()