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