歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

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. }  
Copyright © Linux教程網 All Rights Reserved