How to implement real time dynamic icon like clock/ calendar app in android?

2.7k views Asked by At

In the android clock app icon shows the correct analog real-time in icon, even calendar app icon shows today's date. How to implement real-time icons in apps?

clock icon

1

There are 1 answers

2
Vinay Jayaram On

You have to create a widget application for this to happen,

https://developer.android.com/guide/topics/appwidgets#

ideally you will have a activity with

<activity android:name=".ClockChoice"> 
</activity>

which consists of your Analog clock in your xml something like

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"> 


   <AnalogClock

       android:layout_marginTop="20dp"
       android:layout_marginLeft="120dp"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content" /> 


</RelativeLayout> 

and you add widget following the https://developer.android.com/guide/topics/appwidgets# documentation