I have a problem on my Action bar, I tried to setup a search view on it in order to get a a search bar expandable.
This is woking well except the fact that I had to set all the other menu items with the option ifRoom
in order to let the search field take all the room when the search icon is clicked.
This part also worked well except the fact that too many menu items got pushed into the menu overflow, only 2 icons remained on the vertical screen (including the search bar).
I did another test on another activity having 5 menu items:
- In the first case, I set all of them with
android:showAsAction="always"
- In the second case, I set all of them with ``android:showAsAction="ifRoom"`
Here are the results:
Case 1:
Case 2:
Why if I use ifRoom
, only 2 icons are displayed while actually 5 could easily fill the place?
Because of this, I have only one menu item available beside my search view item...
Thanks!
The maximum of icons for "ifRoom" option is 5 (five) even when I moved to my 100 inch screen size tablet :-) and desperately rotate it on landscape see the link from Jake Wharton's answer (Thank you !) http://developer.android.com/design/patterns/actionbar.html
Looks like its a design decision:
Jake Wharton Says:
From here.
In the XML file, you can request a
MenuItem
to appear as an action item by declaringandroid:showAsAction="ifRoom"
for the<item>
element. This way, theMenuItem
appears in theActionBar
for quick access only if there is room available. If there's not enough room, the item appears in the overflow menu.so you answer is:
You can use
android:showAsAction="always"
to show all menu inActionBar
.