3

I've created a new style to set the background as transparent, but for some reason ever since the app doesn't change layout to landscape when device is rotated. Should I specify something in the new style ?

Here is it's code :

< style name="Transparent" parent="android:@Theme.Translucent">
    < item name="android:windowBackground">@color/background</item>
</style>
SagiLow
  • 5,721
  • 9
  • 60
  • 115

3 Answers3

16

While you are not specify android:screenOrientation for activty, android uses "unspecified" default value, which means that the system chooses the orientation.

In a case you are using style with <item name="android:windowIsTranslucent">true</item>, system selects an orientation based on the orientation of underlying activity in stack. So it's hard to get your application in landscape mode, because most of launchers fixed to portrait.

Just set android:screenOrientation="sensor" for all Translucent activities to force it choose orientation independently:

<activity
    android:name=".SomeActivity"
    android:screenOrientation="sensor"
    ...>
    ...
</activity>
i.shadrin
  • 5,038
  • 2
  • 21
  • 13
  • I have `android:screenOrientation="portrait"` for the background activity. So when I set `android:screenOrientation="sensor"` for foreground translucent activity and rotate to landscape my background activity also rotates despite the fact that it has `android:screenOrientation="portrait"`. How can I force background activity to keep its portrait even though foreground is in landscape mode? – musooff May 08 '19 at 07:10
0

I actually kinda solved it apparently the orientation is according to the background app in case of transparent background, since i kept testing when the Launcher in the back, i always got portrait only.

SagiLow
  • 5,721
  • 9
  • 60
  • 115
  • 1
    Well, just using a different activity behind it doesn't really solve the problem. What if you have an activity on top of the launcher, that is translucent and you want to rotate? screenOrientation=sensor is a bad solution because it ignores the user's screen lock. – Allison Apr 13 '15 at 23:17
-1

just right in manifest

<activity
            android:name=".Ippin_NewActivity"
            android:configChanges="keyboardHidden|orientation"
            android:label="@string/app_name" >
</activity>
Devangi Desai
  • 1,355
  • 12
  • 17
  • 2
    No change ... Looks like the android:@Theme.Translucent is the cause of the orientation lock – SagiLow Oct 27 '12 at 15:31
  • http://stackoverflow.com/questions/2687712/activity-should-be-transparent-but-has-black-background check it out – Devangi Desai Oct 27 '12 at 15:37
  • I actually kinda solved it apparently the orientation is according to the background app in case of transparent background, since i kept testing when the Launcher in the back, i always got portrait only. – SagiLow Oct 27 '12 at 20:22