Android Question How can I determine how many icons can fit on the Actionbar?

JohnC

Expert
Licensed User
Longtime User
My app puts three items in the top right corner of the Activity using this:

B4X:
Activity.AddMenuItem3

Two are Icons and the third is the text "SAVE".

Normally, you would want to have the SAVE item in the top right corner of the activity. So I add them to the activity line this:

- Icon 1
- Icon 2
- SAVE

And larger screen devices can display all three, with "SAVE" and the right-most item.

But, on smaller devices, they can only fit 2 items, so since the auto-3-dot menu item counts as one item, the activity will only show the Icon 1 and the three dots. Then when you hit the 3-dots, the ICON1 and SAVE appear in the drop-down menu.

But I would rather have the SAVE item be the one that is displayed in the titlebar, and have Icon1 and Icon2 be in the drop-down menu. So, this would require changing the loading order to:

- SAVE
- Icon 1
- Icon 2

So, is there a way to determine ahead of time how many items the current device can display in the title/actionbar *before* I load up the menu so I can select the loading order that best works for what I want to do?
 
Last edited:

JohnC

Expert
Licensed User
Longtime User
Thanks!

I have a HUAWEI - Y538 that gave a 3.89 value, and a Samsung S4 that gave a 4.59, so I set the threshold to 4 and it seems to be working good.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Should you ever need more icons displayed you could check my dgActionBar lib.
It's able to display any number of icons due to its horizontal scrolling.
Note: as explained in its thread dgAB is not a real ActionBar (as per Android definition); it's more a command bar.

udg
 
Upvote 0
Top