我想改變一個活動的背景(或更容易一個textview的背景)異步。設置android背景顏色async
顏色在間隔(這裏是500 MS)後應該改變。我無法通過異步類訪問視圖或textview。
有沒有辦法做到這一點?
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;
}
先後在這樣: '@覆蓋 保護無效doInBackground(時鐘... PARAMS){ 爲( int i = 0; i <10; ++ i){finalId c = i * 10; (){ }); runOnUiThread(new Runnable(){ }); }); try {thread} thread(500); (InterruptedException e){ e.printStackTrace(); } }' – sampa