【问题标题】:Animators may only be run on Looper threads on Sherlock Action Bar动画器只能在 Sherlock 操作栏上的 Looper 线程上运行
【发布时间】:2014-04-02 06:45:43
【问题描述】:

我想在延迟 1 秒后隐藏操作栏,

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

运行代码后崩溃..

android.util.AndroidRuntimeException: 动画只能在 活套线程

这个问题有什么解决办法吗?谢谢。

【问题讨论】:

  • 使用 Handler 和 postDelayed()

标签: android multithreading actionbarsherlock


【解决方案1】:

通过使用解决了它

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

【讨论】:

    【解决方案2】:
    new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
    @Override
    public void run() {
        // Your Code
    }
    }, 1000);
    

    使用它是因为不推荐使用无参数构造函数处理程序。

    【讨论】:

    • 您好@OmKumar Yadav,感谢您对stackoverflow 的贡献,请在您的回答中更加详细,尽可能提供解释。有关提示,请参阅stackoverflow.com/help/how-to-answer
    猜你喜欢
    • 2016-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-31
    • 1970-01-01
    相关资源
    最近更新 更多