下面列出了android.app.TimePickerDialog#setTitle ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void showTimePicker(View view) {
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
boolean is24HourFormat = android.text.format.DateFormat.is24HourFormat(getContext());
TimePickerDialog dialog = new TimePickerDialog(getContext(), (
timePicker, hourOfDay, minutes) -> {
selectedCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
selectedCalendar.set(Calendar.MINUTE, minutes);
Date selectedDate = selectedCalendar.getTime();
String result = DateUtils.timeFormat().format(selectedDate);
textView.setText(result);
listener.onDateSelected(selectedDate);
nextFocus(view);
},
hour,
minute,
is24HourFormat);
dialog.setTitle(label);
dialog.show();
}
private void showTimePicker(View view) {
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
boolean is24HourFormat = android.text.format.DateFormat.is24HourFormat(getContext());
TimePickerDialog dialog = new TimePickerDialog(getContext(), (
timePicker, hourOfDay, minutes) -> {
selectedCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
selectedCalendar.set(Calendar.MINUTE, minutes);
Date selectedDate = selectedCalendar.getTime();
String result = dateFormat.format(selectedDate);
editText.setText(result);
listener.onDateSelected(selectedDate);
nextFocus(view);
date = null;
},
hour,
minute,
is24HourFormat);
dialog.setTitle(binding.getLabel());
dialog.show();
}
private void showTimePicker() {
final Calendar calendar = Calendar.getInstance();
String startTime = QueryPreferences.getSettingServiceStartTime(getContext());
if (startTime != null) {
calendar.setTimeInMillis(Long.parseLong(startTime));
}
TimePickerDialog timePickerDialog = new TimePickerDialog(getContext(),
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int hourOfDay, int minute) {
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
calendar.set(Calendar.MINUTE, minute);
QueryPreferences.setSettingServiceStartTime(getContext(), calendar.getTimeInMillis() + "");
mSettingServiceStartTime.setSummary(SERVICE_START_TIME_FORMAT.format(calendar.getTime()));
}
},
calendar.get(Calendar.HOUR_OF_DAY),
calendar.get(Calendar.MINUTE),
true);
timePickerDialog.setTitle("设置时间");
timePickerDialog.show();
}
public void onClickFromTime(View v) {
sharedPreferences = G.context.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE);
int hour = sharedPreferences.getInt(SHP_SETTING.KEY_SELECTED_HOUR_FROM, 8);
int minute = sharedPreferences.getInt(SHP_SETTING.KEY_SELECTED_MINUTE_FROM, 0);
TimePickerDialog mTimePicker = new TimePickerDialog(G.currentActivity, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
long fNow = (selectedHour * 3600000) + (selectedMinute * 60000);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt(SHP_SETTING.KEY_SELECTED_HOUR_FROM, selectedHour);
editor.putInt(SHP_SETTING.KEY_SELECTED_MINUTE_FROM, selectedMinute);
editor.putLong(SHP_SETTING.KEY_SELECTED_MILISECOND_FROM, fNow);
editor.apply();
callbackFromTime.set("" + selectedHour + ":" + selectedMinute);
}
}, hour, minute, true);//Yes 24 hour time
mTimePicker.setTitle(G.context.getResources().getString(R.string.Select_Time));
mTimePicker.show();
}
public void onClickToTime(View v) {
sharedPreferences = G.context.getSharedPreferences(SHP_SETTING.FILE_NAME, MODE_PRIVATE);
int hour = sharedPreferences.getInt(SHP_SETTING.KEY_SELECTED_HOUR_TO, 8);
int minute = sharedPreferences.getInt(SHP_SETTING.KEY_SELECTED_MINUTE_TO, 0);
TimePickerDialog mTimePicker = new TimePickerDialog(G.currentActivity, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
long fNow = (selectedHour * 3600000) + (selectedMinute * 60000);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt(SHP_SETTING.KEY_SELECTED_HOUR_TO, selectedHour);
editor.putInt(SHP_SETTING.KEY_SELECTED_MINUTE_TO, selectedMinute);
editor.putLong(SHP_SETTING.KEY_SELECTED_MILISECOND_TO, fNow);
editor.apply();
callbackToTime.set("" + selectedHour + ":" + selectedMinute);
}
}, hour, minute, true);//Yes 24 hour time
mTimePicker.setTitle(G.context.getResources().getString(R.string.Select_Time));
mTimePicker.show();
}
@Override
protected void onDialogClosed(final boolean positiveResult) {
if (positiveResult) {
v.set(dp.getYear(), dp.getMonth(), dp.getDayOfMonth());
cv.put(getKey(), v.getTimeInMillis());
if (ul != null) {
ul.onUpdateValue(this);
}
if (dt) {
TimePickerDialog tpd = new TimePickerDialog(getContext(), this,
v.get(Calendar.HOUR_OF_DAY), v.get(Calendar.MINUTE), true);
tpd.setTitle(getTitle());
tpd.setCancelable(true);
tpd.show();
}
}
}
@Override
public void onClick(View view) {
final Calendar c = Calendar.getInstance();
if (date != null)
c.setTime(date);
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
boolean is24HourFormat = DateFormat.is24HourFormat(getContext());
SimpleDateFormat twentyFourHourFormat = new SimpleDateFormat("HH:mm", Locale.getDefault());
SimpleDateFormat twelveHourFormat = new SimpleDateFormat("hh:mm a", Locale.getDefault());
TimePickerDialog dialog = new TimePickerDialog(getContext(), (timePicker, hourOfDay, minutes) -> {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
calendar.set(Calendar.MINUTE, minutes);
Date selectedDate = calendar.getTime();
String calendarTime;
if (is24HourFormat) {
calendarTime = twentyFourHourFormat.format(selectedDate);
editText.setText(calendarTime);
} else {
calendarTime = twelveHourFormat.format(selectedDate);
editText.setText(calendarTime);
}
listener.onDateSelected(selectedDate);
nextFocus(view);
}, hour, minute, is24HourFormat);
dialog.setTitle(label);
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getContext().getString(R.string.date_dialog_clear), (timeDialog, which) -> {
editText.setText(null);
listener.onDateSelected(null);
});
dialog.show();
}
@Override
public void onClick(View view) {
activate();
final Calendar c = Calendar.getInstance();
if (date != null)
c.setTime(date);
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
boolean is24HourFormat = DateFormat.is24HourFormat(getContext());
SimpleDateFormat twentyFourHourFormat = new SimpleDateFormat("HH:mm", Locale.getDefault());
SimpleDateFormat twelveHourFormat = new SimpleDateFormat("hh:mm a", Locale.getDefault());
TimePickerDialog dialog = new TimePickerDialog(getContext(), (timePicker, hourOfDay, minutes) -> {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
calendar.set(Calendar.MINUTE, minutes);
Date selectedDate = calendar.getTime();
String calendarTime;
if (is24HourFormat) {
calendarTime = twentyFourHourFormat.format(selectedDate);
editText.setText(calendarTime);
} else {
calendarTime = twelveHourFormat.format(selectedDate);
editText.setText(calendarTime);
}
listener.onDateSelected(selectedDate);
nextFocus(view);
date = null;
}, hour, minute, is24HourFormat);
dialog.setTitle(label);
dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getContext().getString(R.string.date_dialog_clear), (timeDialog, which) -> {
editText.setText(null);
listener.onDateSelected(null);
date=null;
});
dialog.show();
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final TimePickerDialog tp = new TimePickerDialog(getActivity(), this, this.hour, this.minute,
DateFormat.is24HourFormat(getActivity()));
if (title != null) tp.setTitle(title);
return tp;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final TimePickerDialog tp = new TimePickerDialog(getActivity(), this, this.hour, this.minute,
DateFormat.is24HourFormat(getActivity()));
if (title != null) tp.setTitle(title);
return tp;
}
public void onSetTime(View v) {
TimePickerDialog picker = new TimePickerDialog(v.getContext(),
TimePickerDialog.THEME_DEVICE_DEFAULT_LIGHT, (p, hour, minute) -> {
App.dispatch(new CountdoneAction(CountdoneAction.Type.SET_DURATION, (hour * 60 + minute ) * 60 * 1000L));
}, (int) App.state().currentTask().remainder()/60/60/1000,
(int) (App.state().currentTask().remainder()/60/1000)%60, true);
picker.setTitle(R.string.set_time_title);
picker.show();
}