在textview android中显示特定时间的背景色

在textview android中显示特定时间的背景色,android,textview,Android,Textview,在我的应用程序中,我使用gcm更新数据。首先数据保存在数据库中,然后显示在文本视图中。我需要的是,当数据更新时,我只需更改文本视图的背景色2秒钟。请帮助我。U可以使用处理程序: final View v = findViewById(R.id.yourView); // Change the color v.setBackgroundColor(color1); Handler h = new Handler ; h.postAtTime(new Runnable(){ @Over

在我的应用程序中,我使用gcm更新数据。首先数据保存在数据库中,然后显示在文本视图中。我需要的是,当数据更新时,我只需更改文本视图的背景色2秒钟。请帮助我。

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);

首先创建一个可运行的类

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
看看这个:如果你想平滑的改变颜色。