How to dismiss/close/collapse SearchView in ActionBar in MainActivity?

前端 未结 6 2021
无人共我
无人共我 2021-01-07 17:54

I\'m trying to clear and close SearchView after entering a value. I found a solution but it closes the search and won\'t perform any action if I try to search again.

6条回答
  •  遥遥无期
    2021-01-07 18:27

    It sounds like what you are looking for is a way to close the search bar programmatically. Unfortunately, there is not a method or an equivalent workaround for this. You may have already seen another post that had some suggestions, but no real way to do this.

    Your first edit above that calls setIconified(true) is the best alternative. The docs suggest calling setIconified(true) should collapse the search widget, clear it, and remove it from focus if the attribute iconifiedByDefault is true (which it is by default so I don't see any problem with your activity_main_actions.xml).

提交回复
热议问题