There is this widget for the ActionBar which called \'SearchView\'. When it\'s not in use, it looks like this:
I was searching for a solution to expand SearchView programmatically because I need to restore expand state. No one solution was worked for me. Except using Handler().post(). I know it's not a good practice to use post(). But I'm working on legacy project and this workaround is acceptable for me.
Initialize variables block
val searchMenuItem = menu.findItem(R.id.menu_search_item)
val searchView = searchMenuItem.actionView as SearchView
How to expand SearchView:
Handler().post {
searchMenuItem.expandActionView()
}
Reason why post() helps: if your app is not well written it may doing too much work on UI thread. post() ensures that your block of code will be executed when UI thread will be available for execution. Which means if you are using this workaround you can notice small delay between SearchView expanding