I have looked around SO and found how to lock my entire application to Landscape by editing the Manifest file. However, this is not what I want.
I want every activity to be locked portrait, except for one, which will be locked to landscape.
In your manifest file, find your Activity declaration and use the following:
<activity
android:name=".ActivityName"
android:label="#string/app_name"
android:screenOrientation="landscape" >
</activity>
Related
I am trying to setRequestOrientation to a portrait but Activity rotates to landscape and set to portrait when auto-rotate enabled.
The Activity will support both landscape and portrait mode.
The problem will happen above Android 7.0.
Try setting the screen orientation to follow the previous set orientation like this
<activity
android:name="com.my.example.MyActivity"
android:screenOrientation="behind" >
</activity>
Set it to behind.
The default android:screenOrientation is unspecified. This means
The default value. The system chooses the orientation. The policy it uses, and therefore the choices made in specific contexts, may differ from device to device.
In some tablets, for example, the default that the system will choose is landscape, so the system may be auto-rotating to landscape as soon as you start the activity, and then flipping from landscape to portrait when you do your setRequestOrientation.
So to prevent the system from behaving this way, you could try choosing the android:screenOrientation for each of those activities in your android manifest like:
<activity
android:name="com.my.example.MyActivity"
android:screenOrientation="locked" >
</activity>
or
<activity
android:name="com.my.example.MyActivity"
android:screenOrientation="behind" >
</activity>
depending on your app requirements. See the Google documentation for more information on these and other options.
I have a problem to lock the orientation of my app in portrait mode. I added android:screenOrientation="portrait" and android:configChanges="orientation" to my Manifest. Moreover, I added setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) in the onCreate(...) of my MainActivity. The MainActivity is extended by AppCompatActivity. At any time, it works, so you never see your app in the landscape orientation, except when you install it for the first time on your device. Then it is possible to change between landscape and portrait orientation. Does anybody know why this happens? Thank you in advance.
Don't apply the orientation to the application element, instead you should apply the attribute to the activity element, and you must also set configChanges as noted below.
Example:
<activity
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden">
</activity>
This is applied in the manifest file AndroidManifest.xml.
In one of my application, there are multiple Activity(s),
Mostly all activities are configured to be in Landscape orientation by providing android:screenOrientation="sensorLandscape" for each activity
in android manifest file. But one of the activity called 'MyDashBoardActivity' changes orientation to Portrait automatically, when that Activity starts in one of my Android device, but it works fine (Loads in Landscape orientation as expected) in other devices.
How can troubleshoot this issue.
remove this android:screenOrientation="sensorLandscape"
And write In your onCreate :
after setContentView();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Try myActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
or
<activity android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden" android:name="MyDashBoardActivity"/>
I want to run my application always in portrait mode. I searched and found the code below, then I added to manifest file.
android:configChanges="orientation"
android:screenOrientation="portrait"
but my application still chancing orientation when I press CRTL+F12 on AVD.
How can I force my application always run in portrait mode?
Ps: I tried the code reverse. (Second line first then first line)
Did you add that in the activity element, not the application element?
<activity
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden" >
</activity>
My app has a handful of windows. After each of those windows is created, I have code whose intent is to lock those windows in portrait mode:
var win = Ti.UI.createWindow({ ... });
win.orientationModes = [ Ti.UI.PORTRAIT ];
I still can't believe that there isn't a more universal way of doing this for Android, but that's a gripe for another day. :-) For now, this is mostly working. I'm hoping someone here can help me remove the mostly qualifier.
The app opens with a tab group containing 4 tabs. If I rotate my device as soon as the default active tab is loaded, the layout rotates as well. Oops. In fact, if I go immediately to any of those tabs and rotate my device, the layout rotates. More oops.
However -- and this is the fun part -- if I relaunch the app and jump first to a secondary window, one loaded from one of the tab windows, and rotate my phone, no display rotation. Yay! Now I jump back to any of the tab windows, the ones that were rotating before, they no longer rotate.
Wat?!
That's the pattern I think I'm seeing right now. Anyone seen this before? I'm guessing that it's a tab group thing, but I don't see any orientation accessors in the API. Any guidance would be much appreciated.
Thanks.
You'll want to add this to your tiapp.xml
<android >
<manifest>
<application>
<activity android:name="org.appcelerator.titanium.TiActivity" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation">
</activity>
</application>
</manifest>
</android>
That will lock your entire app into portrait mode
Create a custom AndroidManifest.xml through the help of this
and add this line in Application Blog
<application
android:debuggable="false"
android:icon="#drawable/appicon"
android:label="iVite"
android:name="IviteApplication" >
<activity
android:configChanges="keyboardHidden"
android:name="org.appcelerator.titanium.TiActivity"
android:screenOrientation="portrait"/>
<activity
android:configChanges="keyboardHidden"
android:name="ti.modules.titanium.ui.TiTabActivity"
android:screenOrientation="portrait"/>
<activity
android:name="ti.modules.titanium.ui.android.TiPreferencesActivity"/>
</application>
This is right way to use. Because, In Tabbar Application. We have also need to set Tabbar Activity and its orientation Setting. Like in above code In above Code.
Here, both Activity Orientation is set through AndroidManifest.xml.
TabbarActivity and Window Activity.
Cheers....