no orientation notification when translucent set

2019-05-29 00:57发布

Using phones that have android 2.1 & 2.2 installed, using the simplest case of a hello world app and add android:theme="@android:style/Theme.Translucent" to the activity in the android manifest to have the app be transparent, the app sticks as portrait only and won't rotate to landscape when the phone is rotated.

Take the line out and the app rotates ok. This is verified by adding the override of onConfigurationChanged and putting a breakpoint in that routine. Brk hits when translucent isn't applied, doesn't when you add translucency.

However, using a samsung galaxy tab using andr 2.2, rotation works ok even with translucent applied. Anyone have any ideas on this?

2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-05-29 01:29

I had a same problem. Just add android:screenOrientation="sensor" in the manifest file after you specify theme:

    <activity
        android:name=".SplashActivity"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Translucent.NoTitleBar"
        android:screenOrientation="sensor">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

So far I tested it on android 2.2 and 4.1 - works as expected.

查看更多
地球回转人心会变
3楼-- · 2019-05-29 01:31

I have a same problem... but in my case I used Translucent because I solve redrawn warning (this warning appear when set color on android:background)

I solved the warning creating a Theme with parent Theme.Lignt and rewrite two attributes

Something like this

<style name="MyTheme" parent="android:Theme.Light">
    <item name="android:windowBackground">@color/my_background</item>
    <item name="android:colorBackground">@color/my_background</item>        
</style>

If you need use Translucent in ApiDemos has a sample when an activity have a translucent theme and orientation service works well

查看更多
登录 后发表回答