-
-
Save kbshl/9578e0b45570482b9b3f to your computer and use it in GitHub Desktop.
Android orientation locking for Titanium - Originally posted on http://bencoding.com/2016/02/11/android-orientation-locking-for-titanium/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Next you will need to tell Alloy to only create Windows with a portrait | |
* orientation. This is super easy and can be done by adding one class to your | |
* app.tss as shown below. | |
*/ | |
"Window" : { | |
orientationModes :[ | |
Ti.UI.PORTRAIT | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q: Why lock at the Android Activity level, isn’t adding the Alloy style enough? | |
A: Unfortunately no. The Alloy style is applied after the window is created. So | |
if the device is held in a landscape orientation you will see the window open and | |
turn. Locking at the Android Activity level stops this behavior. | |
Q: Does this mean all of my Ti.UI.Window object will be locked in portrait? | |
A: Yes, this locks both at the Android Activity and Titanium object levels. | |
Q: Can I later change the orientation by updating my Ti.UI.Window orientation? | |
A: No, orientation is locked at the Android Activity level as well. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
add android:screenOrientation="portrait|landscape" to each of your activity tags | |
Example: | |
--> | |
<?xml version="1.0" encoding="UTF-8"?> | |
<android xmlns:android="http://schemas.android.com/apk/res/android"> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" > | |
<application> | |
<activity | |
android:configChanges="keyboardHidden|orientation|screenSize" | |
android:screenOrientation="portrait" | |
android:name=".[REPLACE_ME]Activity"> | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN"/> | |
<category android:name="android.intent.category.LAUNCHER"/> | |
</intent-filter> | |
</activity> | |
<activity | |
android:configChanges="keyboardHidden|orientation|screenSize" | |
android:name="org.appcelerator.titanium.TiActivity" | |
android:screenOrientation="portrait"/> | |
<activity | |
android:configChanges="keyboardHidden|orientation|screenSize" | |
android:name="org.appcelerator.titanium.TiTranslucentActivity" | |
android:screenOrientation="portrait" android:theme="@style/Theme.AppCompat.Translucent"/> | |
</application> | |
</manifest> | |
</android> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment