【发布时间】:2019-09-03 00:59:25
【问题描述】:
我已尝试检索 Android 应用的日期,但由于某种原因,它没有按预期显示。我希望日期在应用程序中可见。我尝试在 XML 文件中使用 TextView 和 TextClock 类型(两者都应该产生相同的结果)。仍然没有运气。“@+id/current_real_time”确实出现在应用程序中并且确实显示了实时时间(尽管只有小时和分钟)。但是,“@+id/current_date”似乎没有出现在任何地方。背景是深蓝色。所以 android:textColor 不是这里的问题。
''''
<TextClock
android:id="@+id/current_real_time"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:format12Hour="hh:mm:ss a"
android:textColor="#ffffff"
android:textSize="16pt"
android:textStyle="bold"
android:layout_marginStart="25dp">
</TextClock>
''''
<TextView
android:id="@+id/current_date"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=""
android:textSize="16pt"
android:textColor="#ffffff"
android:textStyle="bold" />
''''
''''
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activated_ticket_layout);
//Matching logic to the UI element (add ticket menu)
ticketToolbar = (Toolbar) findViewById(R.id.addTicketToolbar);
setSupportActionBar(ticketToolbar);
getSupportActionBar().setTitle("Add New Tickets");
ticketToolbar.setNavigationIcon(R.drawable.back_arrow);
//toolbar.setNavigationIcon(R.drawable.plus);
//Adding and Formatting time
Calendar calendar = Calendar.getInstance();
String currentTime = DateFormat.getTimeInstance().format(calendar.getTime());
TextClock textClockTime = (TextClock) findViewById(R.id.current_real_time);
textClockTime.setText(currentTime);
Calendar ticketDate = Calendar.getInstance();
Date currentTicketDate = ticketDate.getDate();
''''
【问题讨论】:
标签: java android date calendar