在我的项目中,我使用TimepickerDialog
在TextView
中显示时间。我的Timepickerdialog
显示为时钟,但我希望其显示为微调框。我该怎么办?
答案 0 :(得分:1)
使用此代码
TimePickerDialog picker = new TimePickerDialog(MainActivity.this,android.R.style.Theme_Holo_Light_Dialog_NoActionBar,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker tp, int sHour, int sMinute) {
//eText.setText(sHour + ":" + sMinute);
}
}, 2, 3, false);
picker.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
picker .show();
答案 1 :(得分:0)
为旋转器模式添加android:timePickerMode = "1"
和
android:timePickerMode="2"
用于时钟模式。
修改
像这样在TimePickerDialog的构造函数中使用主题
TimePickerDialog timePickerDialog = new TimePickerDialog(DateTimePickerDialogActivity.this, android.R.style.Theme_Holo_Light_Dialog, onTimeSetListener, hour, minute, is24Hour);
答案 2 :(得分:0)
使用此代码将时间选择器显示为微调器
public void showCustomTimePicker()
{
final Calendar myCalender = Calendar.getInstance();
int hour = myCalender.get(Calendar.HOUR_OF_DAY);
int minute = myCalender.get(Calendar.MINUTE);
TimePickerDialog.OnTimeSetListener myTimeListener = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
if (view.isShown()) {
myCalender.set(Calendar.HOUR_OF_DAY, hourOfDay);
myCalender.set(Calendar.MINUTE, minute);
}
}
};
TimePickerDialog timePickerDialog = new TimePickerDialog(getActivity(), android.R.style.Theme_Holo_Light_Dialog_NoActionBar, myTimeListener, hour, minute, true);
timePickerDialog.setTitle("Choose hour:");
timePickerDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
timePickerDialog.show();
}
答案 3 :(得分:0)
科特琳:
我使用下面的代码将微调器设置为Timepicker。
private fun showTimePicker() {
// Use the current time as the default values for the picker
val c = Calendar.getInstance()
val hour = c.get(Calendar.HOUR_OF_DAY)
val minute = c.get(Calendar.MINUTE)
// date picker dialog
val timeSetListener = TimePickerDialog.OnTimeSetListener { timePicker, hour, minute ->
c.set(Calendar.HOUR_OF_DAY, hour)
c.set(Calendar.MINUTE, minute)
mSelectedTime = SimpleDateFormat("HH:mm").format(c.time)
root.tvTime.text = mSelectedTime
}
val timePickerDialog = TimePickerDialog(requireContext(),AlertDialog.THEME_HOLO_LIGHT, timeSetListener, hour, minute,
DateFormat.is24HourFormat(requireContext()))
timePickerDialog.show()
}
答案 4 :(得分:-2)
TimePickerDialog nTimePickerDialog = new TimePickerDialog(this, 2,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker pTimePicker, int hr, int min) {
TextView.setText(MessageFormat.format("{0}:{1}", hr, min));
}
},
mHour, mMin, false);
nTimePickerDialog.setTitle("Select Intervals");
nTimePickerDialog.show();