Android how to get AppCompat.Translucent type theme with support actionbar?

Edmund Rojas picture Edmund Rojas · Dec 31, 2013 · Viewed 44.5k times · Source

I would like to add the support actionbar to one of my activities, I previously had been using the theme.translucent with this activity but in order to make the support actionbar work I needed to inherit the Theme.AppCompat, I need to maintain a translucent theme in this activity but unfortunately there isnt a Theme.AppCompat.translucent that i can see by default, is there any way that this can be done?

Answer

Cameron Ketcham picture Cameron Ketcham · Feb 1, 2014

You can create a new set of styles to use which have the same properties as Theme.Translucent from themes.xml.

Add the following to your styles.xml file:

<style name="Theme.AppCompat.Translucent">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowAnimationStyle">@android:style/Animation</item>
</style>

You can change the prefix Theme.AppCompat to something else if you want to inherit other things from the theme such as dialog styles etc. For example, a name like Theme.AppCompat.Light.Translucent would have the properties of the Light theme.

To use the new style, set the theme property to @style/Theme.AppCompat.Translucent

<activity
    android:name=".TranslucentActivity"
    android:theme="@style/Theme.AppCompat.Translucent" >
</activity>