how to change app background image in code based on time of day

  • Replies:5
Anthony Me
  • Forum posts: 10

Apr 9, 2017, 9:15:23 PM via Website

I have an open source clock app that I am modifying for my Mom who has memory issues.

What I would like the app to do is change the background image automatically based on time of day. For example, a daytime background, and night background after 4pm

I have done programming in the past in VB, and VB.Net but am just learning java and android development

What code would I need to insert in order to accomplish this?

Thanks

Reply
Mr. Jacob
  • Forum posts: 23

Apr 20, 2017, 10:52:49 PM via Website

You can get current day hour with Calendar:

Calendar calendar = Calendar.getInstance(); 
int hour = calendar.get(Calendar.HOUR_OF_DAY);

This way you can get also seconds etc.

— modified on Apr 20, 2017, 10:53:01 PM

Reply
Anthony Me
  • Forum posts: 10

Apr 21, 2017, 4:25:16 PM via Website

That is a start. Now I have to figure out how to change the baclkground image in code

Reply
Anthony Me
  • Forum posts: 10

May 21, 2017, 6:38:19 PM via Website

Anyone? Still wondering how to do this?

Reply
Dev Lt
  • Forum posts: 54

May 22, 2017, 7:59:26 AM via Website

You have ImageView or what?

Reply
Anthony Me
  • Forum posts: 10

May 22, 2017, 4:04:23 PM via Website

That is what I was going to use.

Reply