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

AndroidAndroid ActionbarAndroid ThemeAndroid Actionbar-Compat

Android Problem Overview


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?

Android Solutions


Solution 1 - Android

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>

Solution 2 - Android

Parama ,

<style name="Theme.AppCompat.Translucent" parent="Theme.AppCompat.NoActionBar">
        <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>

This should be the style header if you want the toolbar to disappear.you can use any parent theme which has NoActionBar for other effects.

Hope this helps

Solution 3 - Android

If we use Translucent for transparent activity. It raises other issues - the color of Msgbox (now white previously black), Default dialog color, the spinners do drop down but do not show the underline and drop-down arrow. The spinners are color black text black; drop-down white drop-down text black and etc. To overcome this problem, you can just use below code

In style

<style name="Theme.AppCompat.Transparent.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
 <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:backgroundDimEnabled">false</item>
</style>



In manifest file

<activity
        android:name=".activity.YourActivityName"
        android:theme="@style/Theme.AppCompat.Transparent.NoActionBar" />

I hope it will help Thanks

Solution 4 - Android

Cameron's answer is a nice hack , but it produced a floating action bar and tinted my status bar, which i didn't wanted . So i added more xml attributes for making status bar transparent(for sdk >=19) and used java code for making action bar invisible.

mainActivity.java :

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getSupportActionBar().hide();
     ...
    }
     ...
}

styles.xml

<style name="AppTheme.TranslucentBG">
    <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>

    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
    
</style>

manifest.xml

<application
    android:icon="@mipmap/ic_launcher"
    ...
    android:theme="@style/AppTheme"
    ...
    >


    <activity android:name=".MainActivity"
        android:theme="@style/AppTheme.TranslucentBG"
        ...
        >
        ...
    </activity>
</application>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEdmund RojasView Question on Stackoverflow
Solution 1 - AndroidCameron KetchamView Answer on Stackoverflow
Solution 2 - AndroidDhaval ChhedaView Answer on Stackoverflow
Solution 3 - AndroidMonikaView Answer on Stackoverflow
Solution 4 - Androiduser4831795View Answer on Stackoverflow