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

后端 未结 4 1116
天涯浪人
天涯浪人 2020-12-07 14:28

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 acti

相关标签:
4条回答
  • 2020-12-07 15:00

    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>
    
    0 讨论(0)
  • 2020-12-07 15:08

    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

    0 讨论(0)
  • 2020-12-07 15:20

    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>
    
    0 讨论(0)
  • 2020-12-07 15:25

    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

    0 讨论(0)
提交回复
热议问题