本文实例为大家分享了Android时分秒倒计时效果的具体代码,供大家参考,具体内容如下
从mian.xml下手:
MainActivity
public class MainActivity extends Activity { private TextView tvtime1,tvtime2,tvtime3; private long time=400; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tvtime1=(TextView)findViewById(R.id.tvtime1); tvtime2=(TextView) findViewById(R.id.tvtime2); tvtime3=(TextView) findViewById(R.id.tvtime3); handler.postDelayed(runnable, 1000); } Handler handler = new Handler(); Runnable runnable = new Runnable() { @Override public void run() { time--; String formatLOngToTimeStr= formatLongToTimeStr(time); String[] split = formatLongToTimeStr.split(":"); for (int i = 0; i0){ handler.postDelayed(this, 1000); } } }; public String formatLongToTimeStr(Long l) { int hour = 0; int minute = 0; int secOnd= 0; secOnd= l.intValue() ; if (second > 60) { minute = second / 60; //取整 secOnd= second % 60; //取余 } if (minute > 60) { hour = minute / 60; minute = minute % 60; } String strtime = hour+":"+minute+":"+second; return strtime; } }
效果图:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。