Implementing SearchView as per the material design guidelines

前端 未结 7 853
梦谈多话
梦谈多话 2020-12-04 05:04

I have been looking for ways to implement a searchview in the activity toolbar (actionbar) as per the material design guidelines.

On clicking on the search icon, the

7条回答
  •  天命终不由人
    2020-12-04 05:35

    Taking a hint from @Zielony's answer I did the following:

    1) Instead if using an ActionBar or ToolBar I built my own layout (basically a RelativeLayout with burger menu, search and other menu buttons and a EditText for search)

    2) Used a theme without an ActionBar, placed my custom layout at the top of the activity so that it appeared like an ActionBar.

    3) In the search button's OnClickListener I do 2 things:

    • Hide the menu buttons and show the 'search' EditText.
    • Add a fragment to display search suggestions and search
    • Show the soft keyboard input

    3) Added OnClickListeners for the other menu buttons.

    4) Added a TextWatcher on the 'search' EditText to display search hints and results from the server.

    This is how it appears now: enter image description here

提交回复
热议问题