Search editText animation like Chrome app

2019-06-18 16:24发布

问题:

I'm trying to make a search editText in the middle of screen,

That whenever pressed, move with animation to the searchView in the toolbar.

Exactly as you can find in new tab of chrome app (v46) for android.

Didn't find any Github example, so any idea how to implement that?

回答1:

I've created a gist to show one way that this can be done: https://github.com/orenothnay/SearchBar

The main component is FocusableEditText (which I adapted from androids searchview widget). It uses a workaround to allow the edit text to lose focus once the user removes the keyboard. and then you just listen to the focus change event and change your UI accordingly.

The caveates are: It must be wrapped in a focus stealing ViewGroup, and must be told to clear focus on pause (else the keyboard stays up).