Android:DigitalClock 删除秒数
我使用这段代码向我的应用程序添加时钟:
<DigitalClock
android:id="@+id/digitalclock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textSize = "30sp"
/>
问题是它还显示秒..有一种简单而快速的方法来隐藏它们吗?我只需要 hh:mm 格式的小时和分钟,而不是 hh:mm:ss!有什么建议吗?谢谢!
I used this code for adding a clock to my app:
<DigitalClock
android:id="@+id/digitalclock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textSize = "30sp"
/>
The problem is that it shows also seconds..there is a simple and fast way for hide those? I need just hours and minutes in hh:mm format instead of hh:mm:ss! any suggestions? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在此处找到了答案,对于其他正在寻找有效答案的人来说,这里是:
DigitalClock.java
更改新
CustomDigitalClock
中的格式字符串在布局 xml 中引用自定义类
在 Activity/fragment 中加载 CustomDigitalClock
Found the answer here, for anyone else looking for a working answer, here it is:
DigitalClock.java
from android sourceChange format strings within new
CustomDigitalClock
Reference custom class within in layout xml
Load CustomDigitalClock within activity/fragment
DigitalClock Javadoc 指出:
从
FIXME
来看,隐藏部分DigitalClock的能力最终可能会实现。我目前在 Javadoc 或源代码中没有找到任何可以实现您想要的功能的内容。除非您想编写自己的扩展 DigitalClock 的类(或者完全是您自己的时钟实现),否则您可以用另一个元素覆盖 DigitalClock 的秒部分(如果它能满足您的目的)。
The DigitalClock Javadoc states:
Judging by the
FIXME
, the ability to hide portions of DigitalClock might be implemented eventually. I didn't find anything currently in the Javadoc or source code that would do what you want it to.Unless you want to write your own class that extends DigitalClock (or your own clock implementation altogether), you could just cover the seconds portion of the DigitalClock with another element if it would serve your purpose.