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!

1 Answers1

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.

dmon
  • 30,048
  • 8
  • 87
  • 96
  • 1
    Make sure you also have an empty menu xml in just `menu/` or you'll get an exception in portrait. – Jake Wharton Apr 03 '12 at 23:46
  • Thanks Jake, you're right. I was kind of assuming he already had a menu :) – dmon Apr 03 '12 at 23:47
  • @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? –  May 27 '12 at 19:38
  • @haibison: If you only use a single file (in `res/menu`) it will use that in all screen/orientation combinations. – dmon Jun 05 '12 at 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 :-) –  Jun 05 '12 at 04:32