我需要DatePicker说“今天”,而不是今天的旋转到今天的日期。我该怎么办?我的DatePicker小部件配置如下 -
<DatePicker android:id="@+id/dueDatePicker"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="130dp"
android:layout_marginRight="80dp"
android:gravity="center_horizontal"
/>
答案 0 :(得分:0)
此代码应显示一般方法:
DatePicker datePicker = (DatePicker) findViewById(R.id.dueDatePicker);
OnDateChangedListener listener = new OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
// Check if its the current date. isCurrentDate() is not a standard method! you have to implement it by yourself!
if(isCurrentDate(dayOfMonth, monthOfYear, year)) {
// Here you can do whatever you want, if its the current date.
view.setTitle("Today");
}
}
};
datePicker.init (day, month, year, listener);
我希望这有点帮助;)