I just cannot make my status bar not blinking when changing between activities and applying a transition.
Activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_basic);
setupTransitions();
}
private void setupTransitions() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
setupEnterTransition();
setupReenterTransition();
setupExitTransition();
setupReturnTransition();
}
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void setupEnterTransition(){
Slide slide = new Slide(Gravity.END);
slide.excludeTarget(R.id.activity_header, true);
setEnterTransition(slide);
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void setupReenterTransition(){
Slide slide = new Slide(Gravity.START);
slide.excludeTarget(R.id.activity_header, true);
setReenterTransition(slide);
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void setupExitTransition(){
Slide slide = new Slide(Gravity.TOP);
slide.excludeTarget(R.id.activity_header, true);
setExitTransition(slide);
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void setupReturnTransition(){
Slide slide = new Slide(Gravity.BOTTOM);
slide.excludeTarget(R.id.activity_header, true);
setReturnTransition(slide);
}
protected void setEnterTransition(Transition transition) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setEnterTransition(setUpTransition(transition, true));
}
}
setExitTransition, setReenterTransition and setReturnTransition look the same but calling the appropiate method, so I'm not copying them.
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Transition setUpTransition(Transition transition){
transition.setDuration(250);
transition.excludeTarget(android.R.id.statusBarBackground, true);
transition.excludeTarget(android.R.id.navigationBarBackground, true);
return transition;
}
I start the transitions as the following:
public void transitionTo(Intent intent){
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
ActivityOptionsCompat transitionActivityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(this);
startActivity(intent, transitionActivityOptions.toBundle());
}else{
startActivity(intent);
}
}
I set the window's background drawable to avoid seeing the screen black when transitions are running.
getWindow().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.backgroundColor)));
So the the problem is that when I pass from Activity1 to Activity2 (they share the same code), the transition is applied and the statusbar does not blink.
However, going back to previous Activity1 by pressing backButton or home item in the toolbar, the transition applies but the status bar blinks.
I've tried the two approaches suggested in this post, but with no success at all.