[英]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.