I created the gist to show one way this can be done: https://github.com/orenothnay/SearchBar
The main component is FocusableEditText (which I adapted from the viewview androids widget). It uses a workaround so that the edit text loses focus when the user removes the keyboard. and then you just listen to the focus change event and change your interface accordingly.
Caveats: this should be wrapped in focus stealing the ViewGroup, and it should be offered to clear focus on pause (otherwise the keyboard stays up).
source share