Android字體閃爍動畫,使用線程和Timer實現
- public class ActivityMain extends Activity {
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- spark();
- }
-
-
- private int clo = 0;
- public void spark() {
- final TextView touchScreen = (TextView) findViewById(R.id.TextView01);// 獲取頁面textview對象
- Timer timer = new Timer();
- TimerTask taskcc = new TimerTask(){
-
- public void run() {
- runOnUiThread(new Runnable() {
- public void run() {
- if (clo == 0) {
- clo = 1;
- touchScreen.setTextColor(Color.TRANSPARENT); // 透明
- } else {
- if (clo == 1) {
- clo = 2;
- touchScreen.setTextColor(Color.RED);
- } else {
- clo = 0;
- touchScreen.setTextColor(Color.GREEN);
- }
- }
- }
- });
- }
- };
- timer.schedule(taskcc, 1, 300); // 參數分別是delay(多長時間後執行),duration(執行間隔)
- }
- }