no orientation notification when translucent set

让人想犯罪 __ 提交于 2020-01-13 19:26:10

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/6911830/no-orientation-notification-when-translucent-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!