How can I exclude an ActionBar when switching between Activity on Android 5.0

In Android 5.0 Lollipop,

I have two kinds of actions A and B. Activity B has a bottom-layer transition using an Overlay ActionBar, but when B shows, the ActionBar also moves from bottom to top.

How can I prevent the transition from moving to a slide. does the system action bar have an id that i can add to the exception target?

thanks!

+6
source share
2 answers

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

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

Unfortunately, the action panel container view identifier is not part of the public API, so if you are not using the AppCompat v7 library (that is, using the official library libraries), you will need to work around this using the following code to get the identifier:

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

Please note that this code will break if the action bar container identifier name changes in a future version of Android. I doubt it will ever change, though ...

See this post for any other related information.

+6
source

My solution is to extend the style with these arguments:

 <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> 

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> 

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 with transitions as you like, only those excluded goals are important.

+5
source

Source: https://habr.com/ru/post/980171/


All Articles