change color according to day night time in android -
i want develop sample app can continuously track time , can update app ui respect time. i.e. if time 9:00 image showing morning , after time interval image looking different.
may not able explain question properly, want achieve in image,
i tried google it, not getting specific method achieve this, suggestion great me.
thanks
here code may solve purpose.the concept simple.just take time want validate calendar class , compare current time , take appropriate action.
textview textview = (textview) findviewbyid(r.id.text); calendar cal = calendar.getinstance(); cal.settimeinmillis(system.currenttimemillis()); cal.set(calendar.hour_of_day, 3); cal.set(calendar.minute, 00); cal.set(calendar.second, 0); long noon_start = cal.gettimeinmillis();//3.00 cal.set(calendar.hour_of_day, 5); cal.set(calendar.minute, 30); long noon_end = cal.gettimeinmillis();//5.30 long = system.currenttimemillis();//current time if(now > noon_start && < noon_end) { //set background here textview.settext("good afternoon"); } else { //set background here textview.settext("good evening"); }
Comments
Post a Comment