Java – Android Application SDK: exclude status bar from transition’s animation

Android Application SDK: exclude status bar from transition’s animation… here is a solution to the problem.

Android Application SDK: exclude status bar from transition’s animation

I

followed Google’s standard Android SDK tutorial and got to the point where I could change the action bar options.

When a different activity is opened, it pops up as an animation (fade in + grow). My problem is that the new action bar in this activity also pops up with the animation (it’s all connected as a container) I want the action bar to remain on top, fixed, and only the app’s content pops up. When the content of the action bar changes, it should just not have any animation changes. Take the Telegram app, for example.

When I followed the standard tutorial, I guessed this was the default behavior, so it might be common to turn it off, but I haven’t found an effective solution to this anywhere, so I must have overlooked some very basic settings.

Topic .xml:

...
<style name="BlaTheme"
       parent="@style/Theme.AppCompat">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="android:actionBarTabTextStyle">@style/MyActionBarTabText</item>
    <item name="android:actionMenuTextColor">@color/actionbar_text</item>
    <item name="android:background">@color/darkpurple</item>
    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/MyActionBar</item>
    <item name="actionBarTabTextStyle">@style/MyActionBarTabText</item>
    <item name="actionMenuTextColor">@color/actionbar_text</item>
    <item name="android:windowActionBar">true</item>  
    <item name="android:windowContentOverlay">@null</item>
</style>

<!-- ActionBar styles -->
<style name="MyActionBar"
       parent="@style/Widget.AppCompat.ActionBar">
    <item name="android:background">@android:color/transparent</item>
    <item name="android:titleTextStyle">@style/MyActionBarTitleText</item>
    <!-- Support library compatibility -->
    <item name="titleTextStyle">@style/MyActionBarTitleText</item>
</style>
...

Solution

You can define your transition like this:

  1. In the fade.xml file:

    <?xml version="1.0" encoding="utf-8"?>
    <transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
        <fade android:duration="500">
            <targets>
                <!--excluding status bar--> 
                <target android:excludeId="@android:id/statusBarBackground"/>
                <!--excluding navigation bar-->
                <target android:excludeId="@android:id/navigationBarBackground"/>
                <!--excluding toolbar bar-->
                <target android:excludeId="@id/toolbar"
            </targets>
        </fade>
    </transitionSet>
    

Then set it to:

    Transition mFadeTransition =
            TransitionInflater.from(this).
                    inflateTransition(R.transition.fade);

getWindow().setEnterTransition(mFadeTransition);
  1. Or just java:

    Fade fade = new Fade();
    fade.setDuration(500);
    exclude toolbar
    fade.excludeTarget(R.id.toolbar, true);
    exclude status bar
    fade.excludeTarget(android. R.id.statusBarBackground, true);
    exclude navigation bar
    fade.excludeTarget(android. R.id.navigationBarBackground, true);
    
    getWindow().setEnterTransition(fade);
    

Related Problems and Solutions