View.post(Runnable)
mTextView.post(new Runnable() { @Override public void run() { mTextView.setText("yes, 获取到数据了!#"); mTextView.setBackgroundColor(Color.BLUE); } });
View.postDelay(Runnable , long)
Android View 都有一个postDelayed(Runnable,毫秒数),用于延迟UI操作的方法,下面的代码中就是300毫秒之后,calendar_view才显示
private void method() { blur_view.setBackgroundColor(Color.BLACK); blur_view.postDelayed(new Runnable() { public void run() { calendar_view.setVisibility(View.GONE); CalendarActivity.this.finish(); } }, 300); }
5秒倒计时:
num = (TextView) findViewById(R.id.num); num.postDelayed(new Runnable() { @Override public void run() { num.setText("" + index); index--; if (index == 0) { Intent intent = new Intent(MainActivity.this, SecondActivity.class); startActivity(intent); } else { num.postDelayed(this, 1000); } } }, 1000);