随时间更改文本颜色

时间:2013-03-17 20:31:28

标签: java android

我希望我的文字颜色每秒都会改变,但我实际上并不知道如何开始做某事,这取决于传递时间。你能举几个例子,或说我应该用什么方法?也许我可以阅读以了解更多信息?

2 个答案:

答案 0 :(得分:1)

首先,请查看TimerTimerTask类。例如,要定期运行蜂鸣声,您可以使用以下内容:

timer.schedule(new RemindTask(),
        1250,        //initial delay
        1*100);  //subsequent rate

}

更改文字颜色 - 各种方法......

Source

Android timer class

Android textColor won't change colour

答案 1 :(得分:1)

这样的事情可以解决问题,并且不需要使用TimerTimerTask

public class Test
{
    public static void main(String... args)
    {
        Thread thread = new Thread()
        {

            public void run()
            {
                while (true){
                    Random myColor = new Random();
                    TextView tv = tv.setTextColor(Color.rgb(myColor.nextInt(255), myColor.nextInt(255), myColor.nextInt(255)));
                    try
                    {
                        Thread.sleep(1000); // 1 second
                    } catch (Exception e)
                    {
                        e.printStackTrace();
                    }
                }
            }
        };
        thread.start();
    }
}
相关问题