Animators may only be run on Looper threads on She

2019-04-18 22:33发布

问题:

I wanted to hide the action bar after the 1 second delay,

Timer().schedule(new TimerTask() {
                        @Override
                        public void run() {
                                getSupportActionBar().hide();
                        }
                    }, 1000);

Getting crash after I ran the code..

android.util.AndroidRuntimeException: Animators may only be run on Looper threads

Is there any solution for this issue? Thanks.

回答1:

Solved it by using

new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                                getSupportActionBar().hide();
                        }
                    }, 1000);