【发布时间】:2016-09-01 20:47:56
【问题描述】:
我想异步更改活动的背景(或更简单的文本视图的背景)。
颜色应该在一段时间后改变(这里是 500 毫秒)。我无法通过异步类访问视图或文本视图。
有什么办法吗?
private void setColor(int red, int yellow, int blue) {
View view = this.getWindow().getDecorView();
view.setBackgroundColor(Color.rgb(red,yellow,blue));
}
private class DisplayGradient extends AsyncTask<Clock, Void, Void> {
@Override
protected Void doInBackground(Clock... params) {
for(int i = 0; i < 10; ++i) {
try {
setColor(i*10,0,0);
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return null;
}
【问题讨论】:
标签: android android-activity view background-color