Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
706 views
in Technique[技术] by (71.8m points)

android - Action bar - ifRoom option leaving too much space

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...