How do I open the SearchView programmatically?

后端 未结 8 1641
既然无缘
既然无缘 2020-12-02 09:19

There is this widget for the ActionBar which called \'SearchView\'. When it\'s not in use, it looks like this:

\

8条回答
  •  天涯浪人
    2020-12-02 09:26

    For androidx.appcompat.widget.SearchView,

    searchView.setIconifiedByDefault(true)   // didn't work
    
    searchMenuItem.expandActionView()  // didn't work
    
    MenuItemCompat.expandActionView(searchMenuItem) // didn't work
    
    searchView.onActionViewExpanded()  // didn't work
    

    The following worked for me,

    searchView.findViewById(R.id.search_button).performClick()
    

提交回复
热议问题