在更改活动和应用转换时,我无法使状态栏不闪烁。
的活动:
@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和setReturnTransition看起来相同,但调用了适当的方法,所以我没有复制它们。
@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;
}
我按以下步骤开始转换:
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);
}
}
我将窗口的背景设置为drawable,以避免在转换运行时看到屏幕变黑。
getWindow().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.backgroundColor)));
所以问题是当我从Activity1传递到Activity2(它们共享相同的代码)时,将应用转换并且状态栏不会闪烁。
但是,通过按工具栏中的backButton或home项目返回上一个Activity1,转换将适用,但状态栏会闪烁。
我已尝试过post中建议的两种方法,但根本没有成功。