{"id":10806,"date":"2023-12-01T14:51:26","date_gmt":"2023-12-01T06:51:26","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=10806"},"modified":"2023-12-01T14:51:26","modified_gmt":"2023-12-01T06:51:26","slug":"app%e5%bc%80%e5%8f%91%e5%80%92%e8%ae%a1%e6%97%b6%e6%b3%a8%e6%84%8f%e5%93%aa%e4%ba%9b%e7%bb%86%e8%8a%82%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/10806\/","title":{"rendered":"app\u5f00\u53d1\u5012\u8ba1\u65f6\u6ce8\u610f\u54ea\u4e9b\u7ec6\u8282\uff1f"},"content":{"rendered":"
\u5012\u8ba1\u65f6\u662f\u4eba\u4eec\u751f\u6d3b\u4e2d\u5e38\u89c1\u7684\u4e00\u79cd\u5012\u8ba1\u65f6\u65b9\u5f0f\uff0c\u53ef\u4ee5\u901a\u8fc7\u5012\u8ba1\u65f6\u6765\u63d0\u9192\u81ea\u5df1\u5b8c\u6210\u67d0\u4ef6\u4e8b\u60c5\u6216\u8005\u7b49\u5f85\u67d0\u4e2a\u65f6\u95f4\u7684\u6765\u4e34\u3002\u73b0\u5728\uff0c\u968f\u7740\u79fb\u52a8\u4e92\u8054\u7f51\u7684\u53d1\u5c55\uff0c\u8d8a\u6765\u8d8a\u591a\u7684\u4eba\u4eec\u4f7f\u7528app\u6765\u5b9e\u73b0\u5012\u8ba1\u65f6\u529f\u80fd\u3002\u672c\u6587\u5c06\u4ecb\u7ecdapp\u5f00\u53d1\u5012\u8ba1\u65f6\u7684\u539f\u7406\u548c\u8be6\u7ec6\u8fc7\u7a0b\u3002<\/p>\n
\u4e00\u3001\u5012\u8ba1\u65f6\u7684\u539f\u7406<\/p>\n
\u5012\u8ba1\u65f6\u7684\u539f\u7406\u662f\u5229\u7528\u8ba1\u65f6\u5668\uff0c\u5c06\u8bbe\u5b9a\u7684\u65f6\u95f4\u7ecf\u8fc7\u4e00\u5b9a\u7684\u5904\u7406\u540e\uff0c\u5728\u56fa\u5b9a\u65f6\u95f4\u95f4\u9694\u5185\u4e0d\u65ad\u5730\u51cf\u5c11\u3002\u5f53\u65f6\u95f4\u5f52\u96f6\u540e\uff0c\u5c31\u4f1a\u89e6\u53d1\u76f8\u5e94\u7684\u4e8b\u4ef6\uff0c\u5982\u5f39\u51fa\u63d0\u9192\u6216\u8005\u6267\u884c\u81ea\u5b9a\u4e49\u51fd\u6570\u7b49\u3002\u5728app\u5f00\u53d1\u4e2d\uff0c\u5012\u8ba1\u65f6\u7684\u539f\u7406\u4e5f\u662f\u901a\u8fc7\u8ba1\u65f6\u5668\u5b9e\u73b0\u7684\u3002<\/p>\n
\u4e8c\u3001\u5012\u8ba1\u65f6\u7684\u5b9e\u73b0<\/p>\n
1. \u83b7\u53d6\u7cfb\u7edf\u65f6\u95f4<\/p>\n
\u5728\u5012\u8ba1\u65f6\u7684\u5b9e\u73b0\u4e2d\uff0c\u9996\u5148\u9700\u8981\u83b7\u53d6\u7cfb\u7edf\u65f6\u95f4\u3002\u83b7\u53d6\u7cfb\u7edf\u65f6\u95f4\u7684\u65b9\u6cd5\u53ef\u4ee5\u4f7f\u7528Java\u4e2d\u7684System.currentTimeMillis()\u51fd\u6570\uff0c\u5b83\u53ef\u4ee5\u8fd4\u56de\u81ea1970\u5e741\u67081\u65e50\u65f60\u52060\u79d2\u5230\u76ee\u524d\u65f6\u523b\u7684\u6beb\u79d2\u6570\uff0c\u7136\u540e\u901a\u8fc7\u8ba1\u7b97\u53ef\u4ee5\u5f97\u51fa\u76ee\u6807\u65f6\u95f4\u3002<\/p>\n
2. \u8bbe\u7f6e\u5012\u8ba1\u65f6\u65f6\u95f4<\/p>\n
\u83b7\u53d6\u76ee\u6807\u65f6\u95f4\u540e\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u5012\u8ba1\u65f6\u7684\u65f6\u95f4\u3002\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6eTextView\u63a7\u4ef6\u5b9e\u73b0\uff0c\u5c06\u5012\u8ba1\u65f6\u5269\u4f59\u7684\u65f6\u95f4\u663e\u793a\u5728\u754c\u9762\u4e0a\u3002<\/p>\n
3. \u5b9e\u73b0\u5012\u8ba1\u65f6<\/p>\n
\u5012\u8ba1\u65f6\u7684\u5b9e\u73b0\u9700\u8981\u4f7f\u7528\u8ba1\u65f6\u5668\u3002\u53ef\u4ee5\u4f7f\u7528Android\u4e2d\u7684CountDownTimer\u7c7b\u6765\u5b9e\u73b0\u5012\u8ba1\u65f6\u3002CountDownTimer\u662f\u4e00\u4e2a\u62bd\u8c61\u7c7b\uff0c\u9700\u8981\u91cd\u5199onTick()\u548conFinish()\u4e24\u4e2a\u51fd\u6570\u3002<\/p>\n
onTick()\u51fd\u6570\u7528\u4e8e\u6bcf\u6b21\u5012\u8ba1\u65f6\u95f4\u9694\u66f4\u65b0\u65f6\u8c03\u7528\uff0c\u53ef\u4ee5\u5728\u51fd\u6570\u5185\u66f4\u65b0TextView\u663e\u793a\u7684\u5269\u4f59\u65f6\u95f4\u3002<\/p>\n
onFinish()\u51fd\u6570\u7528\u4e8e\u5012\u8ba1\u65f6\u7ed3\u675f\u65f6\u8c03\u7528\uff0c\u53ef\u4ee5\u5728\u51fd\u6570\u5185\u89e6\u53d1\u7279\u5b9a\u4e8b\u4ef6\u3002<\/p>\n
4. \u5f00\u59cb\u5012\u8ba1\u65f6<\/p>\n
\u5012\u8ba1\u65f6\u7684\u5f00\u59cb\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528CounAPP<\/a>tDownTimer\u7c7b\u4e2d\u7684start()\u51fd\u6570\u5b9e\u73b0\u3002\u9700\u8981\u8bbe\u7f6e\u5012\u8ba1\u65f6\u7684\u603b\u65f6\u95f4\u548c\u6bcf\u6b21\u66f4\u65b0\u7684\u65f6\u95f4\u95f4\u9694\uff0c\u5728\u8c03\u7528start()\u51fd\u6570\u4e4b\u540e\uff0c\u5012\u8ba1\u65f6\u5c31\u5f00\u59cb\u4e86\u3002<\/p>\n 5. \u505c\u6b62\u5012\u8ba1\u65f6<\/p>\n \u5f53\u5012\u8ba1\u65f6\u4e0d\u518d\u9700\u8981\u65f6\uff0c\u9700\u8981\u505c\u6b62\u8ba1\u65f6\u5668\u3002\u53ef\u4ee5\u4f7f\u7528CountDownTimer\u7c7b\u4e2d\u7684cancel()\u51fd\u6570\u5b9e\u73b0\u3002\u8fd9\u4e2a\u51fd\u6570\u53ef\u4ee5\u76f4\u63a5\u505c\u6b62\u5012\u8ba1\u65f6\uff0c\u4e5f\u53ef\u4ee5\u5728\u5012\u8ba1\u65f6\u7ed3\u675f\u65f6\u81ea\u52a8\u8c03\u7528\u3002<\/p>\n \u4e09\u3001\u5b9e\u4f8b<\/p>\n \u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u7528\u4e00\u4e2a\u7b80\u5355\u7684\u5b9e\u4f8b\u6765\u6f14\u793a\u5012\u8ba1\u65f6\u7684\u5b9e\u73b0\u3002<\/p>\n 1. \u521b\u5efa\u4e00\u4e2a\u7a7a\u7684Android Studio\u9879\u76ee\uff0c\u547d\u540d\u4e3aCountdownTimerDemo\u3002<\/p>\n 2. \u6253\u5f00activity_main.xml\uff0c\u5728\u5e03\u5c40\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4e00\u4e2aTextView\u63a7\u4ef6\uff0c\u7528\u4e8e\u663e\u793a\u5012\u8ba1\u65f6\u5269\u4f59\u65f6\u95f4\u3002<\/p>\n “`<\/p>\n<\/p>\n android:id=”@+id\/tv_countdown”<\/p>\n \n android:layout_width=”wrap_content”<\/p>\n android:layout_height=”wrap_content”<\/p>\n android:text=”00:00:00″<\/p>\n android:textSize=”50sp”<\/p>\n android:textStyle=”bold”<\/p>\n android:layout_centerInParent=”true”\/><\/p>\n “`<\/p>\n 3. \u5728MainActivity.java\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n “`<\/p>\n public class MainActivity extends AppCompatActivity {<\/p>\n private TextView tv_countdown;<\/p>\n @Override<\/p>\n protected void onCreate(Bundle savedInstanceState) {<\/p>\n super.onCreate(savedInstanceState);<\/p>\n setContentView(R.layout.activity_main);<\/p>\n tv_countdown = (TextView) findViewById(R.id.tv_countdown);<\/p>\n long targetTime = System.currentTimeMillis() + 60 * 1000; \/\/ \u8bbe\u7f6e\u76ee\u6807\u65f6\u95f4\u4e3a60\u79d2\u540e<\/p>\n CountDownTimer timer = new CountDownTimer(targetTime-System.currentTimeMillis(), 1000) {<\/p>\n @Override<\/p>\n public void onTick(long millisUntilFinished) {<\/p>\n long second = millisUntilFinished \/ 1000 % 60;<\/p>\n long minute = millisUntilFinished \/ 1000 \/ 60 % 60;<\/p>\n long hour = millisUntilFinished \/ 1000 \/ 60 \/ 60 % 24;<\/p>\n String time = String.format(“%02d:%02d:%02d”, hour, minute, second);<\/p>\n tv_countdown.setText(time);<\/p>\n }<\/p>\n @Override<\/p>\n public void onFinish() {<\/p>\n tv_countdown.setText(“\u5012\u8ba1\u65f6\u7ed3\u675f”);<\/p>\n }<\/p>\n };<\/p>\n timer.start(); \/\/ \u5f00\u59cb\u5012\u8ba1\u65f6<\/p>\n }<\/p>\n }<\/p>\n “`<\/p>\n \u8fd0\u884c\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u770b\u5230\u5012\u8ba1\u65f6\u6548\u679c\u3002<\/p>\n \u56db\u3001\u603b\u7ed3<\/p>\n \u5012\u8ba1\u65f6\u662fapp\u4e2d\u5e38\u89c1\u7684\u529f\u80fd\u4e4b\u4e00\uff0c\u901a\u8fc7\u4f7f\u7528\u8ba1\u65f6\u5668\u53ef\u4ee5\u5b9e\u73b0\u5012\u8ba1\u65f6\u7684\u529f\u80fd\u3002\u5012\u8ba1\u65f6\u7684\u5b9e\u73b0\u9700\u8981\u83b7\u53d6\u7cfb\u7edf\u65f6\u95f4\u3001\u8bbe\u7f6e\u5012\u8ba1\u65f6\u65f6\u95f4\u3001\u5b9e\u73b0\u5012\u8ba1\u65f6\u3001\u5f00\u59cb\u5012\u8ba1\u65f6\u548cAPP\u5f00\u53d1<\/a>\u505c\u6b62\u5012\u8ba1\u65f6\u7b49\u6b65\u9aa4\u3002\u4f7f\u7528Android\u4e2d\u7684CountDownTimer\u7c7b\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b9e\u73b0\u5012\u8ba1\u65f6\u529f\u80fd\u3002\u672c\u6587\u901a\u8fc7\u4e00\u4e2a\u7b80\u5355\u7684\u5b9e\u4f8b\u6f14\u793a\u4e86\u5012\u8ba1\u65f6\u7684\u5b9e\u73b0\u65b9\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":" \u5012\u8ba1\u65f6\u662f\u4eba\u4eec\u751f\u6d3b\u4e2d\u5e38\u89c1\u7684\u4e00\u79cd\u5012\u8ba1\u65f6\u65b9\u5f0f\uff0c\u53ef\u4ee5\u901a\u8fc7\u5012\u8ba1\u65f6\u6765\u63d0\u9192\u81ea\u5df1\u5b8c\u6210\u67d0\u4ef6\u4e8b\u60c5\u6216\u8005\u7b49\u5f85\u67d0\u4e2a\u65f6\u95f4\u7684\u6765\u4e34\u3002\u73b0\u5728\uff0c\u968f\u7740\u79fb\u52a8\u4e92\u8054\u7f51\u7684\u53d1\u5c55\uff0c\u8d8a\u6765\u8d8a\u591a\u7684\u4eba\u4eec\u4f7f\u7528app\u6765\u5b9e\u73b0\u5012\u8ba1\u65f6\u529f\u80fd\u3002\u672c\u6587\u5c06\u4ecb\u7ecdapp\u5f00\u53d1\u5012\u8ba1\u65f6\u7684<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[3515,6677,570,13729,16532],"topic":[],"class_list":{"0":"post-10806","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-appkf","7":"tag-3515","8":"tag-app","9":"tag-570","11":"tag-16532"},"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/10806","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=10806"}],"version-history":[{"count":1,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/10806\/revisions"}],"predecessor-version":[{"id":10839,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/10806\/revisions\/10839"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=10806"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=10806"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=10806"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=10806"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}<\/figure>\n<\/p>\n