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

  • Replies:5
  • OpenNot stickiedUnanswered
  • 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?


  • 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

  • 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

  • Forum posts: 10

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

Anyone? Still wondering how to do this?

  • Forum posts: 54

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

You have ImageView or what?

  • Forum posts: 10

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

That is what I was going to use.

Recommended by NextPit