- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在尝试以 24 小时格式显示时间时遇到问题。我已经让它显示另一个时区的时间,但我无法让它以 24 小时格式显示。
<TextClock
android:id="@+id/hk_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timeZone="GMT+0800"
android:format24Hour="MMM dd, yyyy k:mm" />
也可以使用 TextClock 显示日期吗?
最佳答案
如果您的系统处于 12 小时模式,您不必编写子类来获得您想要的东西。 JavaDocs说:
- In 12-hour mode:
- Use the value returned by getFormat12Hour() when non-null
- Otherwise, use the value returned by getFormat24Hour() when non-null
- Otherwise, use a default value appropriate for the user's locale, such as HH:mm
因此,我希望最后一行使 getFormat12Hour()
返回 null
并因此使用您自定义的 getFormat24Hour()
格式:
<android.widget.TextClock
android:id="@+id/hk_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timeZone="GMT+0800"
android:format24Hour="MMM dd, yyyy k:mm"
android:format12Hour="@null" />
(顺便说一句,正如其他人所提到的,强制格式应谨慎使用。如果您的用户想要 24 小时制,他们会在他们的系统首选项中指定这一点。以及强制使用数字格式、颠倒日期的应用程序他们的用户的格式,如 MM/dd/yyyy
,邀请一星评级(除了,在这种情况下,来自美国和菲律宾用户),所以你使用 是件好事MMM
!您最好还是使用 getBestDateTimePattern() ,不过,我相信这需要子类化 TextClock。)
关于android - 如何使用 TextClock 以 24 小时格式显示时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15367620/
当我在布局 Android Studio 布局预览中创建 TextClock 小部件时,没有显示更改。但在调试设备上小部件工作得很好。如果我评论它布局预览工作成功。另一台PC上的Android Stu
in this i am trying to get only hour from the textclock and show on my widget and it works perfectly
我想在我的 Android 应用程序中使用 TextClock 来显示用户历史记录。目前我正在使用 TextView 显示时间,但为了更好地支持时区和小时格式,我正在考虑使用 TextClock。 我
我的 TextClock 设置如下: 现在即使我的手机默认为 12 小时制,它也显示为 24 小时制。 我希望能够将其设置为 12 小时时区,但不是永久设置,仅与我的手机设置有关。我怎样才能做到这一
我必须设置一个 TextClock 来在另一个 TextClock 中显示时间和日期。我希望能够让用户更改日期的格式。例如。他们想要的不是 dd MMMM yyyy:MMMM dd yyyy 将显示
当我在布局 Android Studio 布局预览中创建 TextClock 小部件时,没有显示更改。但在调试设备上小部件工作得很好。如果我评论它布局预览工作成功。另一台PC上的Android Stu
我目前在我的 xml 中使用 TextClock,但是我不希望 AM/PM 在显示的时间。有办法去除吗? 最佳答案 基于documentation您可以使用以下内容: setFormat12Hour(
随着 API 级别 17 的发布,我开始了解 TextClock 小部件,它与数字时钟有何不同? 最佳答案 DigitalClock 随 API 级别 17 的发布而弃用。此外,建议在处理 API 级
TextClock是一个用于 Android XML 布局的小部件,它可以自行保存和显示时间。您只需添加格式和时区。 现在我在 Jetpack Compose 中看不到类似的东西。 我应该自己使用可组
我在 android 中有一个 TextClock,它应该仅以 12 小时格式显示系统时间。问题是它以 24 小时格式显示,即使系统本身以 12 小时格式显示。我已经在我的 TextView 中使用了
我在 hh:mm:ss 格式中使用 TextClock 来显示当前时间。但是当我将语言环境从英语更改为西类牙语时,TextClock 以错误的格式给出时间,即 hh:mm。这仅在 Samsung Ta
我开发了一个小部件应用程序。每个小部件都有一个 TextClock,我想为每个文本时钟设置时区,但是 RemoteViews 不支持设置时区。 如何设置时区? 最佳答案 使用 RemoteViews
我在尝试以 24 小时格式显示时间时遇到问题。我已经让它显示另一个时区的时间,但我无法让它以 24 小时格式显示。 也可以使用 TextClock 显示日期吗? 最佳答案 如果您的系统处于 12 小
我已将 minSdkVersion 级别设置为 8,这将允许 Froyo 的每个人安装和使用该应用程序,但是当我尝试将 TextClock View 添加到 Activity xml 文件时,它说该
我已经创建了一个 TextClock 小部件来显示运行时间。 在布局中 在 Activity 中,创建引用 textClock = (TextClock) findViewById(R.id
我正在使用 TextClock 来显示今天是哪一天和哪一天。 是否可以更改 TextClock 的默认语言(英语)? 显示: 最佳答案 您可以通过编写自定义 TextClock 并在
我正在为 API 级别 8 到 19 的设备制作应用程序,其中包含时钟。我试图将 DigitalClock 放到布局中。我从 Eclipse 收到消息,该类自 API 级别 17 起已弃用,建议使用
我是一名优秀的程序员,十分优秀!