Translucent Theme Does Not Work When Set Programmatically On Android 2.3.3 Or 4.2
Solution 1:
There's a lot of discussion on setTheme() or rather why setTheme() isn't working as expected:
- https://code.google.com/p/android/issues/detail?id=4394
- https://code.google.com/p/android/issues/detail?id=3793
- https://groups.google.com/forum/?fromgroups=#!topic/android-developers/vSZHsVWUCqk
- Why getApplicationContext().setTheme() in a Activity does not work?
Quintessential to that discussion is that the setTheme doesn't work well while setting the theme in the manifest does (even Dianne Hackborn recommends to use the manifest way over the setTheme() way, see third link above). This is especially true when it comes to defining the background. Results you get in the emulator or in the graphical layout editor can unfortunately not be transferred to the real world (speak actual devices). So what you see in your 4.0.3 emulator might not be the same on a real device (as you already noticed ;-).
If there's no specific reason to use setTheme to theme your Activity then I would recommend to change your manifest like this:
<activityandroid:name=".TranslucentActivity"android:theme="@android:style/Theme.Translucent"/>
You can still use the setTheme to theme other elements of your layout but I haven't found any other working solution when it comes to creating transparent or dialog like activities.
Solution 2:
<activityandroid:theme="@android:style/Theme.Translucent.NoTitleBar"android:name="com.example.translucencytest.MainActivity" ><intent-filter><actionandroid:name="android.intent.action.MAIN" /><categoryandroid:name="android.intent.category.LAUNCHER" /></intent-filter></activity><activityandroid:theme="@android:style/Theme.Translucent.NoTitleBar"android:name="com.example.translucencytest.TranslucentActivity"></activity>
Post a Comment for "Translucent Theme Does Not Work When Set Programmatically On Android 2.3.3 Or 4.2"