Android: How do I display an updating clock in a TextView

前端 未结 6 977
时光说笑
时光说笑 2020-12-08 02:49

have a clock I want to display in a TextView.

I would have thought there was a few nice functions to do this, but I couldn\'t find anything. I ended up implementing

6条回答
  •  猫巷女王i
    2020-12-08 03:39

    I recommend TextClock (From API 17), also please dont use DigitalClock (Deprecated from API 17) as it will cause MEMORY LEAK and will lead to Out of Memory Exception. Please add the following piece of code to corresponding layout.xml file

     
    

    This will do the trick, also please note that you can format the displaying time as required for example for getting in 12 hour format with seconds you can use "android:format12Hour="hh:mm:ss a"".

提交回复
热议问题