Android實(shí)現(xiàn)時(shí)鐘特效
本文實(shí)例為大家分享了Android實(shí)現(xiàn)時(shí)鐘特效的具體代碼,供大家參考,具體內(nèi)容如下
效果展示:
功能介紹:
如果您想換一張背景圖,可以點(diǎn)擊左下角按按鈕切換背景圖片。
如果您不想看見右上方的日期,可以點(diǎn)擊它,他就會(huì)隨即隱藏。如果你想 再次查看,請(qǐng)點(diǎn)擊左下角切換壁紙按鈕他就會(huì)被再次展示。
Demo 下載地址:
點(diǎn)擊此處跳轉(zhuǎn):AndroidClockDemo
部分代碼展示:
mainActivity部分:
實(shí)現(xiàn)切換,獲得事件并顯示等功能。
public class MainActivity extends AppCompatActivity { private int[] imageIds = new int[]{ R.drawable.bac_1, R.drawable.bac_2, R.drawable.bac_3, R.drawable.bac_4 }; private int num = 1; //num用于確定背景圖 private boolean flagI = true;//i 用于控制日期顯隱 private ImageView imageView; private TextView textView; private TextView textViewDate; private Handler handler = new Handler(){ @Override public void handleMessage(Message msg) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");// HH:mm:ss //獲取當(dāng)前時(shí)間 Date date = new Date(System.currentTimeMillis()); textView.setText("" + simpleDateFormat.format(date)); simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");// HH:mm:ss textViewDate.setText("" + simpleDateFormat.format(date)); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); transparency();//系統(tǒng)狀態(tài)欄透明 textView = (TextView) findViewById(R.id.txt); imageView = (ImageView) findViewById(R.id.background); textViewDate = (TextView) findViewById(R.id.date); refreshTime(); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } //事件刷新線程 private void refreshTime(){ new Thread(){//每秒更新時(shí)間 @Override public void run() { while (true){ Message meg = new Message(); handler.sendMessage(meg); try { sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } }.start(); } //日期顯隱點(diǎn)擊事件 public void show(View view){ if(flagI) { textViewDate.setVisibility(View.GONE); flagI = false; }//重新顯現(xiàn)方法在背景按鈕上 } //懸浮按鈕 更換背景 public void change(View view){ imageView.setImageResource(imageIds[num++]); num %= 4; textViewDate.setVisibility(View.VISIBLE); flagI = true; } //設(shè)置系統(tǒng)菜單為透明 private void transparency(){ if (Build.VERSION.SDK_INT >= 21) { View decorView = getWindow().getDecorView(); decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); getWindow().setStatusBarColor(Color.TRANSPARENT); } } }
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android打造屬于自己的時(shí)間鐘表
- Android自定義控件實(shí)現(xiàn)時(shí)鐘效果
- Android獲取設(shè)備CPU核數(shù)、時(shí)鐘頻率以及內(nèi)存大小的方法
- android實(shí)現(xiàn)widget時(shí)鐘示例分享
- Android多功能時(shí)鐘開發(fā)案例(實(shí)戰(zhàn)篇)
- Android 仿日歷翻頁、仿htc時(shí)鐘翻頁、數(shù)字翻頁切換效果
- android高仿小米時(shí)鐘(使用Camera和Matrix實(shí)現(xiàn)3D效果)
- Android多功能時(shí)鐘開發(fā)案例(基礎(chǔ)篇)
- Android實(shí)現(xiàn)簡(jiǎn)單時(shí)鐘View的方法
- Android自定義鐘表特效
相關(guān)文章
Android中關(guān)于FragmentA嵌套FragmentB的問題
這篇文章主要為大家詳細(xì)介紹了Android中關(guān)于FragmentA嵌套FragmentB的問題,感興趣的小伙伴們可以參考一下2016-08-08Android實(shí)現(xiàn)點(diǎn)擊AlertDialog上按鈕時(shí)不關(guān)閉對(duì)話框的方法
這篇文章主要介紹了Android實(shí)現(xiàn)點(diǎn)擊AlertDialog上按鈕時(shí)不關(guān)閉對(duì)話框的方法,涉及設(shè)置監(jiān)聽的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-02-02Android實(shí)現(xiàn)布局動(dòng)畫和共享動(dòng)畫的結(jié)合效果
今天給大家?guī)砟軌蛱嵘脩趔w驗(yàn)感的交互動(dòng)畫,使用起來非常簡(jiǎn)單,體驗(yàn)效果非常贊,其中僅使用到布局動(dòng)畫和共享動(dòng)畫,文章通過代碼示例介紹的非常詳細(xì),感興趣的同學(xué)可以自己動(dòng)手試一試2023-09-09Android編程實(shí)現(xiàn)調(diào)用相冊(cè)、相機(jī)及拍照后直接裁剪的方法
這篇文章主要介紹了Android編程實(shí)現(xiàn)調(diào)用相冊(cè)、相機(jī)及拍照后直接裁剪的方法,涉及Android拍照及圖形處理相關(guān)操作技巧,需要的朋友可以參考下2017-02-02android notification 的總結(jié)分析
notification是一種出現(xiàn)在任務(wù)欄的提示,特別是在4.0以后notification改進(jìn)了不少,本文內(nèi)容都是基于4.0及4.1以后總結(jié)來的2013-05-05