Android字体闪烁动画(线程)


Android字体闪烁动画,使用线程和Timer实现

  1. public class ActivityMain extends Activity {  
  2.     public void onCreate(Bundle savedInstanceState) {  
  3.         super.onCreate(savedInstanceState);  
  4.         setContentView(R.layout.main);  
  5.         spark();  
  6.     }  
  7.   
  8.   
  9.     private int clo = 0;  
  10.     public void spark() {  
  11.         final TextView touchScreen = (TextView) findViewById(R.id.TextView01);// 获取页面textview对象   
  12.         Timer timer = new Timer();  
  13.         TimerTask taskcc = new TimerTask(){  
  14.   
  15.             public void run() {  
  16.                 runOnUiThread(new Runnable() {  
  17.                     public void run() {  
  18.                         if (clo == 0) {  
  19.                             clo = 1;  
  20.                             touchScreen.setTextColor(Color.TRANSPARENT); // 透明   
  21.                         } else {  
  22.                             if (clo == 1) {  
  23.                                 clo = 2;  
  24.                                 touchScreen.setTextColor(Color.RED);  
  25.                             } else {  
  26.                                 clo = 0;  
  27.                                 touchScreen.setTextColor(Color.GREEN);  
  28.                             }  
  29.                         }  
  30.                     }  
  31.                 });  
  32.             }  
  33.         };  
  34.         timer.schedule(taskcc, 1300); // 参数分别是delay(多长时间后执行),duration(执行间隔)   
  35.     }  
  36. }  

相关内容