Action Item shown only in Landscape?

Go To StackoverFlow.com

0

I was just wondering if it were at all possible for an Action Bar icon to only be shown when the device is in landscape mode? In portrait I have an onscreen button for a certain task, but in order to take advantage of all of the screen-space in landscape, that button won't fit. So I was wondering if I could put it in the Action Bar, but it would only be necessary when the device is in landscape.

Thanks!

2012-04-03 23:25
by roboguy12


5

You can define a specific menu XML for when the activity is in landscape orientation by putting it inside the /res/menu-land folder.

2012-04-03 23:40
by dmon
Make sure you also have an empty menu xml in just menu/ or you'll get an exception in portrait - Jake Wharton 2012-04-03 23:46
Thanks Jake, you're right. I was kind of assuming he already had a menu : - dmon 2012-04-03 23:47
thank you, it worked perfectly - roboguy12 2012-04-04 00:24
@JakeWharton Excuse me, I think it's not necessary. In my case I have only one menu declared in res/menu, and the app works fine in both screen mode. Do you have a link to Android documentation - NoName 2012-05-27 19:38
@haibison: If you only use a single file (in res/menu) it will use that in all screen/orientation combinations - dmon 2012-06-05 03:44
@dmon I know. I've never tested. But I think an empty menu is not necessary. If you have a menu in /res/menu-land, but not in /res/menu, you can check in onCreateOptionsMenu() and just don't load it. Anyway, now I got him, with an empty menu, you don't need to check screen orientation. There are many ways for a target :- - NoName 2012-06-05 04:32
Ads