0
在我的應用程序中,我使用gcm來更新數據。首先數據保存在數據庫中,然後顯示在文本視圖中。我需要的是,當數據更新時,我必須將textview的背景顏色更改爲2秒。請幫助我。在textview中顯示特定時間的背景顏色android
在我的應用程序中,我使用gcm來更新數據。首先數據保存在數據庫中,然後顯示在文本視圖中。我需要的是,當數據更新時,我必須將textview的背景顏色更改爲2秒。請幫助我。在textview中顯示特定時間的背景顏色android
U可以使用一個處理程序:
final View v = findViewById(R.id.yourView);
// Change the color
v.setBackgroundColor(color1);
Handler h = new Handler ;
h.postAtTime(new Runnable(){
@Override
public void run() {
// Change color after 2 seconds
v.setBackgroundColor(color2);
}
}, 2000);
首先創建一個Runnable類
private Runnable revertTextViewColor = new Runnable() {
public void run() {
textView.setBackgroundColor(Color.WHITE); //Put your original color here
}
};
然後當數據庫被更新和TextView中需要強調 變化的TextView的顏色
textView.setBackgroundColor(Color.BLUE); //Put any color here
Handler customHandler = new Handler(); //Create a handler
customHandler.postDelayed(revertTextViewColor , 2000); //Schedule the color to revert to original color in 2 secs i.e. 2000ms
看看這個:http://developer.android.com/guide/topics/graphics/prop-animation.htm l如果你想平滑改變顏色。 – weston