How do I open the SearchView programmatically?

后端 未结 8 1639
既然无缘
既然无缘 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:35

    Expanding the answer of Matthias Robberts:

    I wanted a list fragment to keep it's search value and set it after user returns from other fragment.

    if (myViewModel.filterTextSaved.isNotEmpty()) { // Kotlin, storing state in ViewModel
        searchItem.expandActionView() // needs to come first, otherwise empty text
        theTextArea.setText(courseViewModel.filterTextOnClick)
    }
    

    and for the menu I keep always|collapseActionView, otherwise it stays open when user deletes the text.

提交回复
热议问题