【问题标题】:How change activity background color [closed]如何更改活动背景颜色
【发布时间】:2013-10-19 17:28:51
【问题描述】:

我有一个叫做颜色的按钮。如何每 5 秒更改一次 Activity 背景颜色?

【问题讨论】:

    标签: android colors background


    【解决方案1】:

    快速谷歌搜索: How to set background color of an Activity to white programmatically?

    将其放入带有Thread.sleep(5000) 的循环中,并使用设置所需颜色的函数将其包装起来。

    【讨论】:

      【解决方案2】:

      不要让线程休眠,这是一种不好的做法在布局中创建父视图的对象 并在下面的方法中使用 Async 任务在固定间隔后更新 UI

       protected void onProgressUpdate(Integer... progress) {
               // interact with UI here
           }
      

      see the docs 用于 AsyncTask 实现。

      【讨论】:

        【解决方案3】:

        你可以使用TimerTask

        例如

        Time timer = new Timer();
        timer.scheduleAtFixedRate( new TimerTask(){
                        public void run(){
                          //here set background
                        }
                        },0,5000);
        

        更多详情,http://developer.android.com/reference/java/util/Timer.html

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-08-03
          • 2018-09-14
          • 2020-03-06
          • 2012-06-14
          相关资源
          最近更新 更多