How can I style the SearchView when using a Toolbar as an Action Bar?

前端 未结 4 2036
灰色年华
灰色年华 2020-12-23 14:55

I\'m using a Toolbar as an Action Bar in my app using the AppCompat v21 library, as described in this post on the Android Developers Blog. I\'ve styled the acti

4条回答
  •  北海茫月
    2020-12-23 15:05

    After digging into the source code and experimenting a bit, I've come up with a solution and cleared up a couple of sources of confusion. First, the SearchView style needs to be set in the app theme:

    
    

    Then we need to set the suggestionRowLayout in the searchViewStyle:

    
    

    In my question, I assumed that we could use @style/Widget.AppCompat.Light.SearchView to get a light suggestion menu, but it turns out that this isn't the case; we need to define our own layout. I based mine on abc_search_dropdown_item_icons_2line.xml from the AppCompat v21 library.

提交回复
热议问题