0

How can I possible set landscape mode throughout my application ? I can add android:screenOrientation="landscape"

in my all activities. But then its very redundant code and it possible be error prone as the application evolves. Can't I set landscape mode for my whole application in one place only ?

LearningBasics
  • 660
  • 1
  • 7
  • 24

4 Answers4

1

Make an AbstractActivity that all your activities extends. This will set the orientation programmaticaly for all of them.

public abstract class LandscapeActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
}
stevyhacker
  • 1,847
  • 2
  • 23
  • 31
0

In short, you can't. Adding it to the application element does nothing. You have no alternative to adding it to each activity.

scottt
  • 8,301
  • 1
  • 31
  • 41
  • Are you sure ? Though I also could not find something which could be set once. – LearningBasics Aug 21 '14 at 12:36
  • Ha! Nothing is certain with Android development. But yeah, I'm sure. There's no known way to accomplish a full application setting of orientation via the manifest. At least not at the time of writing this and up though version 19. There *are* ways of doing it via extending a custom abstract Activity base class or by subclassing the Application class, but those don't seem worth the effort unless you need them for another reason. – scottt Aug 21 '14 at 12:45
-1
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

also see Android, landscape only orientation?

Community
  • 1
  • 1
robotik
  • 9
  • 3
-1

Yes you can do this both programmatically and for all your activities making an AbstractActivity that all your activities extends.

public abstract class AbstractActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
}

This abstract activity can also be used for a global menu.

  • 1
    Edited my answer !! Although my answer is almost the same as yours –  Aug 21 '14 at 12:46
  • When you copy the answer please mention the source from where you copied. Copied from http://stackoverflow.com/questions/6745797/how-to-set-entire-application-in-portrait-mode-only – Aniruddha Aug 22 '14 at 03:55