I would like to achieve the following - a SearchView with a button that gets sent to an overflow when the SearchView is expanded:
There is a known bug with SearchView that causes it to not respect the positioning of other elements in the toolbar (related: this question). This means that even if the rightmost icon is set to ifRoom, it will not be sent to the overflow menu and will instead get pushed off the edge of the screen and appear cut off.
The solution mentioned in the bug report is to add the SearchView programmatically using actionBar.setCustomView instead of through XML. When I try that, however, I get the following - the SearchView is shortened and the button is still displayed, even though it is set to ifRoom (setting the SearchView width to Integer.MAX_VALUE has no effect):
When I try programmatically adding the SearchView to the options menu with menu.add, the results are the same as through modifying the XML.
Is there a way I can achieve what I want?

