Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i exclude ActionBar when transitions between Activities on Android 5.0

On Android 5.0 Lollipop,

I have two activities A and B. Activity B has a slie enter transition from bottom with a Overlay ActionBar, but when B shows, the ActionBar also slide from bottom to top.

How can i prevent the actionbar from slide transition. does system actionbar has an id that i can add to the exclude target ?

thanks!

like image 481
tinyao Avatar asked Dec 26 '14 14:12

tinyao


People also ask

Which of the following transitions is a shared elements transition in Android?

Android also supports these shared elements transitions: changeBounds - Animates the changes in layout bounds of target views. changeClipBounds - Animates the changes in clip bounds of target views. changeTransform - Animates the changes in scale and rotation of target views.

What is transition in Android?

The Android transitions framework allows you to configure the appearance of changes in your app's user interface. You can animate changes in an app screen, defining each phase as a scene and controlling the way in which the transition changes the app appearance from one scene to another.


2 Answers

If you are using the AppCompat v7 library, it is easy:

View decor = getWindow().getDecorView();
int actionBarId = R.id.action_bar_container;
enterTransition.excludeTarget(decor.findViewById(actionBarId), true);

Unfortunately, the action bar container view ID is not part of the public API, so if you are not using the AppCompat v7 library (i.e. you are using the official framework libraries) you will need to work around this by using the following code to retrieve the ID instead:

int actionBarId = getResources().getIdentifier("action_bar_container", "id", "android");

Note that this code will break if the action bar container's ID name changes in a future version of Android. I doubt it will ever change though...

See this post for some other related information.

like image 102
Alex Lockwood Avatar answered Sep 25 '22 09:09

Alex Lockwood


My solution is to extend the style with this args:

<item name="android:windowActivityTransitions">true</item>
<item name="android:windowContentTransitions">true</item>
<item name="android:windowEnterTransition">@transition/slide</item>
<item name="android:windowExitTransition">@transition/slide</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">@transition/enter</item>
<item name="android:windowSharedElementExitTransition">@transition/enter</item>

This here is my res/transition/slide.xml:

<?xml version="1.0" encoding="utf-8"?>
<slide xmlns:android="http://schemas.android.com/apk/res/android" android:slideEdge="bottom">
    <targets>
        <target android:excludeId="@android:id/statusBarBackground"/>
        <target android:excludeId="@android:id/navigationBarBackground"/>
    </targets>
</slide>

This here is my res/transition/enter.xml:

<?xml version="1.0" encoding="utf-8"?>
<transitionSet
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:targetSdkVersion="19"
    android:transitionOrdering="sequential">
    <targets>
        <target android:excludeId="@id/action_bar_container"/>
        <target android:excludeId="@android:id/statusBarBackground"/>
    </targets>
    <changeBounds/>
    <changeTransform/>
    <changeClipBounds/>
    <changeImageTransform/>
</transitionSet>

You can play around with that transitions as you like, important is just those excluded targets.

like image 38
rekire Avatar answered Sep 21 '22 09:09

rekire