19

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:

  1. In the first case, I set all of them with android:showAsAction="always"
  2. In the second case, I set all of them with ``android:showAsAction="ifRoom"`

Here are the results:

Case 1:

always case

Case 2:

ifRoom case

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!

Yoann Hercouet
  • 17,894
  • 5
  • 58
  • 85
  • Why if I use ifRoom, only 2 icons are displayed?? ----> http://stackoverflow.com/a/15832302/1168654 – Dhaval Parmar May 27 '13 at 11:32
  • I checked your link, but it does not answer my question. I know it is related to the screen size, but here I have for example far enough space for more than 2 icons. – Yoann Hercouet May 27 '13 at 11:37
  • In the XML file, you can request a menu item to appear as an action item by declaring android:showAsAction="ifRoom" for the element. This way, the menu item appears in the action bar for quick access only if there is room available. If there's not enough room, the item appears in the overflow menu. hope you understand. for more detail check this: http://developer.android.com/guide/topics/ui/actionbar.html – Dhaval Parmar May 27 '13 at 11:40
  • Yes I have that, the other options appear in the overflow menu, but I would prefer if they could remain on the action bar. The menu overflow is not directly reachable. – Yoann Hercouet May 27 '13 at 11:45
  • 1
    @DhawalSodhaParmar I think his problem (and mine too) is not about the "ifRoom" setting, but about the fact that there appears to be enough room for the icons however Android is putting them in the overflow menu (presumably because Android doesn't think there is enough room). – micheal65536 Oct 17 '15 at 11:38

3 Answers3

14

Looks like its a design decision:

Jake Wharton Says:

When contained within the action bar there is a finite maximum of action items based on the device's density-independent width. The action items can also not cover more than half the width of the action bar.

From here.

Archie.bpgc
  • 23,812
  • 38
  • 150
  • 226
  • 2
    Thanks, I did not know this limit was in place. I found out that here are detailed some examples and the number of icons displayed: http://developer.android.com/design/patterns/actionbar.html – Yoann Hercouet May 27 '13 at 11:55
0

In the XML file, you can request a MenuItem to appear as an action item by declaring android:showAsAction="ifRoom" for the <item> element. This way, the MenuItem appears in the ActionBar 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:

use "ifRoom" to request that an item appear in the action bar, but allow the system to move it into the overflow menu when there's not enough room.(when space is limited on smaller screens).

You can use android:showAsAction="always" to show all menu in ActionBar.

Sufian
  • 6,405
  • 16
  • 66
  • 120
Dhaval Parmar
  • 18,812
  • 8
  • 82
  • 177
  • Thanks but as explained above, I would prefer the icons to be displayed in the visible action bar and not in the overflow if there is room available for it. – Yoann Hercouet May 27 '13 at 11:46
  • i explain here because you understand why we can't show all icons in actionbar using ifroom. in sort you can't do that using 'ifroom' – Dhaval Parmar May 27 '13 at 11:50
0

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

Dorin
  • 37
  • 7