我正在使用一个非常标准的睡眠循环,每次增加100毫秒,但我想在中途添加文本颜色变化......但是,我收到一个错误。以下代码中是否存在问题?
public class splashActivity extends Activity {
TextView tv;
LinearLayout ll;
protected boolean _active=true;
protected int _splashTime=5000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
tv=(TextView)findViewById(R.id.textViewSplash);
ll=(LinearLayout)findViewById(R.id.linearLayoutSplash);
Thread splashThread = new Thread(){
@Override
public void run() {
try{
int waited=0;
while (_active && waited < _splashTime){
sleep(100);
if(_active){
waited += 100;
}
if(waited >=2500){
tv.setTextColor(Color.GREEN);
}
}
}
catch(InterruptedException e){
}
finally{
finish();
startActivity(new Intent("com.kleaverdevelopment.splashTest.SplashTest.mainActivity")); //package.package.package.appName.nextActivity
stop();
}
}
};
splashThread.start();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
_active = false;
}
return true;
}
}