gpt4 book ai didi

android-studio - Android Studio 3.1.1 中的时间和日期选择器在哪里?

转载 作者:行者123 更新时间:2023-12-05 07:34:58 26 4
gpt4 key购买 nike

我刚刚升级到 Android Studio 3.1.1,现在找不到时间和日期选择器。

我在 Linux 机器上运行,Android Studio 建议升级,我只是点击了“确定”。下面是我的调色板的屏幕截图:

enter image description here

知道在哪里可以找到它们吗?我在找这两个人:

enter image description here

谢谢!

最佳答案

我想你要找的是 DatePickerDialog 和 TimePickerDialog。您可以通过编程方式添加它。本例中的 onclick edittext 事件。对于 DatePickerDialog :

    final Calendar myCalendar = Calendar.getInstance();

final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {

@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
myCalendar.set(Calendar.YEAR, year);
myCalendar.set(Calendar.MONTH, monthOfYear);
myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);

String myFormat = "dd/MM/yyyy"; //set date format
SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);

YourDateEditText.setText(sdf.format(myCalendar.getTime()));
}

};

YourDateEditText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new DatePickerDialog(YourActivity.this, date, myCalendar
.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH)).show();
}
});

对于 TimePickerDialog :

YourTimeEditText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Calendar mcurrentTime = Calendar.getInstance();
int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
int minute = mcurrentTime.get(Calendar.MINUTE);

TimePickerDialog mTimePicker;
mTimePicker = new TimePickerDialog(YourActivity.this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
YourTimeEditText.setText( selectedHour + ":" + selectedMinute);
}
}, hour, minute, true);
mTimePicker.setTitle("Select Time");
mTimePicker.show();
}
});

关于android-studio - Android Studio 3.1.1 中的时间和日期选择器在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49866922/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com