要让TextClock显示当前的日期和时间,可以通过设置TextClock的format属性来显示所需的日期和时间格式。例如,可以设置format为"yyyy-MM-dd HH:mm:ss"来显示当前的年月日时分秒。具体步骤如下:
<TextClock android:id="@+id/textClock" android:layout_width="wrap_content" android:layout_height="wrap_content" android:format24Hour="yyyy-MM-dd HH:mm:ss" android:format12Hour="yyyy-MM-dd hh:mm:ss a" /> TextClock textClock = findViewById(R.id.textClock); textClock.setFormat12Hour("yyyy-MM-dd hh:mm:ss a"); textClock.setFormat24Hour("yyyy-MM-dd HH:mm:ss"); 这样就可以让TextClock显示当前的日期和时间。