I'm adding a SubMenu at runtime and everything works great.
I just have a problem: how to set showAsAction="always"
on a runtime-added SubMenu?
There is no method to achieve that and if don't set it I can't find any way to have it shown in the Action Bar.
Thanks for helping
Asked
Active
Viewed 467 times
2

Francesco Ambrosini
- 481
- 6
- 21
-
Possible duplicate of http://stackoverflow.com/questions/15138305/set-androidshowasaction-ifroomwithtext-programmatically – woot Jan 31 '14 at 15:13
-
no.. same as one of the answers below i'm trying to set showAsAction to a SubMenu not to a MenuItem. – Francesco Ambrosini Jan 31 '14 at 16:13
3 Answers
4
Don't know if this is too late or not, but SubMenu has as function called getItem() which returns a MenuItem. You can then get this MenuItem, and call setShowAsAction() afterwards. Hope this helps!!!

cwhite
- 41
- 2
1
Call yourSubMenu.getItem()
. This give you MenuItem that represent the SubMenu.

deW1
- 5,562
- 10
- 38
- 54

Rodrigo Daros
- 13
- 4
0
If im right then
MenuItem = item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

FD_
- 12,947
- 4
- 35
- 62

Jerry Wattre
- 204
- 2
- 8
-
yeah i thought that but SubMenu is not a MenuItem, isn't it? In your answer you're calling setShowAsAction on a MenuItem not on a SubMenu – Francesco Ambrosini Jan 31 '14 at 16:11
-
1How can I try it? I have `SubMenu menu;` from here how should I call your `MenuItem.setShowAsAction()`? Do you mean calling it on one of the child items of my SubMenu? – Francesco Ambrosini Jan 31 '14 at 16:17