How to make the application work only in portrait mode, and when turning the screen nothing happens?
How to make the application work only in portrait mode, and when turning the screen nothing happens?
Just add it to your AndroidManifest.XML android:screenOrientation="portrait"
:
<activity android:name=".SomeActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" />
In addition to the way Leofontes has demonstrated by setting the android:screenOrientation
attribute to portrait
in its <activity>
found in AndroidManifest.xml
, you can also programmatically insert using the setRequestedOrientation . Here's an example:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Then it would look like this onCreate()
:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
Note : A while back Google has released a note that applications that work only in one mode, being portrait or landscape , would be less visible to download (when I find the news I leave the link here). So it's important, you think about these issues, to create layouts that support the two guidelines simultaneously.