【问题标题】:Delay hiding and showing ActionBar?延迟隐藏和显示 ActionBar?
【发布时间】:2013-05-27 18:26:32
【问题描述】:

我想在活动启动时隐藏操作栏,当用户触摸屏幕时显示几秒钟,然后再次隐藏。

我想出的就在下面,但我想知道是否有更好的办法(忽略一些风格问题:幻数、逻辑重复等)。

我正在使用 actionbarsherlock。

谢谢

可运行 hideActionbarRunnable = new Runnable() { @覆盖 公共无效运行(){ ActionBar bar = getSupportActionBar(); bar.hide(); } }; 可运行 showActionbarRunnable = new Runnable() { @覆盖 公共无效运行(){ ActionBar bar = getSupportActionBar(); bar.show(); } }; Runnable animateActionBarHide = new Runnable() { @覆盖 公共无效运行(){ handler.postDelayed(hideActionbarRunnable,3000); } }; Runnable animateActionBarShow = new Runnable() { @覆盖 公共无效运行(){ handler.post(showActionbarRunnable); handler.postDelayed(hideActionbarRunnable,3000); } }; @覆盖 受保护的无效 onResume() { 超级.onResume(); Log.i(MainActivity.TAG,"CameraActivity: onResume 调用"); 线程 t = new Thread(animateActionBarHide); t.start(); } @覆盖 公共布尔 onTouchEvent(MotionEvent 事件){ ActionBar bar = getSupportActionBar(); if(event.getAction() == MotionEvent.ACTION_DOWN) { 线程 t = 新线程(animateActionBarShow); t.start(); } 别的 { 线程 t = new Thread(animateActionBarHide); t.start(); } 返回 super.onTouchEvent(event); }

【问题讨论】:

    标签: android android-actionbar actionbarsherlock


    【解决方案1】:

    Handler 类有一个方法postDelayed(Runnable r, long delayMillis)。这将使它更短,更优雅。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多