Android: Optionsmenu 'More-list' with icon

2019-04-12 08:57发布

问题:

I love how Android automaticly displays a number of menuitems in the options menu and when there are too many for your screen, it displays a 'More' button. I'd like to keep it that way, but the menuitems in the popup that you get when you press 'More' don't have the menuicons. Is there a way that I can overrule this? If not, how can I display my own popup when the user clicks 'More'? I still want that Android figures out how many menuitems fit on the users screen.

Thanks a lot! Erik

回答1:

Is there a way that I can overrule this?

No, sorry. The overflow menu, like context menus, do not have icons.

If not, how can I display my own popup when the user clicks 'More'?

Step #1: Put in five menu items

Step #2: Put in a sixth menu item, named "More", with an appropriate icon

Step #3: When the user taps the "More" item, do whatever you want (e.g., AlertDialog)

I still want that Android figures out how many menuitems fit on the users screen.

At present, the rule is always "6". Since you know how many menu items you want, you can determine for yourself whether you need your own implementation of "More".

It is possible that Android will start supporting more option menu choices as screen sizes get bigger. However, until that happens, we have no way of predicting how best to meet your desired goal, or if it is even possible.



标签: android menu