First, please help me rephrase the title to suits the issue better, for others to find.
This question has been asked here but has been answered not to my satisfaction, and I will explain why.
Note: I use the v7-AppCompat Support Library ~v22
with a Toolbar
and setSupportActionBar(toolbar)
Question
How to constrain an ActionView
(SearchView in my case) of an expanded MenuItem
to fill parent but not push other MenuItem
s outside of scope.
Obvious (not good enough) Answers
In code, we can use
MenuItemCompat.expandActionView(item);
on the item, but:
a. When expanded, the "back" button is shown on top of theDrawerToggle
. This doesn't really solve it.
b. On back presses theSearchView
will collapse again.As known, setting
iconifiedByDefault(false)
on theSearchView
, along withapp:showAsAction="ifRoom|collapseActionView"
makes it expanded (and with some side effects), but: see '1' above.
My Current Solution
I use a custom width factor (~0.7) on the 2nd solution, forcing the SearchView
to be as width as (Toolbar
's width) * (factor).
This is somewhat fine, but sometimes fails (I guess menu is not fully prepared), and it IS possible, having that normally expanding the SearchView
(1st solution) leads to the desired width.
Another thing I have tried:
Setting the SearchView
as the Toolbar
's custom layout, instead of a MenuItem
. But than it starts collapsed and I can't seem to expand it. Also, I would like to do this the "right" way and not use custom layouts.
I will gladly put some more code in if that helps in any way.
Thx!