Breaking News
Home / Android / Android Snippets / How to set the screen orientation to Portrait for an Android Activity?

How to set the screen orientation to Portrait for an Android Activity?

By default an Activity support both Portrait and Landscape mode. On changing the orientation of the device, view rotates accordingly. However in certain apps we may want to limit the orientation to Portrait or Landscape and we can do the same by specifying the android attribute screenOrientation to portrait or landscape as part of the Activity definition:

Example:

<activity android:name=”.activity.AudioPlayerScreen”
android:label=”Audio Player” android:screenOrientation=”portrait”]]>
<intent-filter]]>
<action android:name=”android.intent.action.MAIN”/>
<category android:name=”android.intent.category.DEFAULT”/>

This will set the orientation of Audio Player Screen to Portrait mode only.<!>

[pb_builder]

Check Also

How to check if an Android device can connect to Internet?

The following code snippet shows how to check if an Android device can connect to …

Leave a Reply