简体   繁体   English

如何使用 Kotlin 在 Android 工作室更改问候语 textView 即早安或晚安

[英]how to change greeting textView i.e, Good morning or Good night in Android studio using Kotlin

这是我的应用程序的屏幕截图

I am making an app in kotlin language.我正在用 kotlin 语言制作应用程序。 I want to change that Good morning textview to good evening when time is between 4 pm to 8pm and goodnight when time is in range of night time and agin to good morning when time pasts 12 am.我想将早上 4 点到晚上 8 点之间的早安 textview 更改为晚安,当时间在夜间范围内时,我想将晚安更改为早上 12 点之后的早安。

how can i do it in kotlin?我怎么能在 kotlin 中做到这一点?

Simply get hour like this:只需像这样得到小时:

val currentHour = Calendar.getInstance().get(Calendar.HOUR)

And set text, based on the hour.并根据小时设置文本。

text.text = if(currentHour > 20 && currentHour < 4) "Good evening" else "Good morning"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以编程方式更改 textView 的颜色以在 Android Studio 上形成良好的对比? - How to change the color of a textView programmatically for a good contrast on Android Studio? 如何在 Android TextView 中使用“&amp;”即和符号 - How to have "&" i.e and symbol in Android TextView How to move from one activity to another ie Java Class to Kotlin Class in an Android Java Project? - How to move from one activity to another i.e Java Class to Kotlin Class in an Android Java Project? 如何使用Android Studio在音频播放器中保存音频播放器的当前播放时间(即1:45/25:40)? - how to save the audio player current play time i.e 1:45/25:40 in audio player using android studio? 要实现Android夜间模式,使用UiModeManager并启用汽车模式,但显示通知,可能不是好方法 - To implement Android night mode, using UiModeManager and enable car mode, but show a notification, it may not the good way 在Android Detect中,早上,晚上,晚上 - In Android Detect morning,evening,night hours 如何在 Android Studio 预览中切换夜间模式和灯光模式? - How can I change between night mode and light mode on Android Studio preview? 如何在幕后在android中发送彩信 以编程方式? - How to send MMS in android behind the scene i.e; programmatically? 在 Android Studio(Kotlin)中单击按钮更改 TextView 文本 - Change TextView text on button click in Android Studio ( Kotlin) 如何存储android sms?。在文件系统中,即message1.extension或在数据库中,即sqlite - How are android sms stored?.In a file system i.e message1.extension or in a database i.e sqlite
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM