How do you create an Android timepicker without a cancel button? I would had expected setCancelable(false) would do this, but does not get rid of the button, it only seems to prevent cancellations from clicking outside of the window or back button.
If you'd like to use the TimePickerDialog, it is pretty simple. You just simply need to detect when the dialog is shown, look up the NEGATIVE button since that serves the "Cancel" one and set it's visibility to GONE..like this:
final TimePickerDialog timePicker = new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// Do something with the time
}
}, 12, 25, true); // 12 is the hour and 25 is minutes..please change this
timePicker.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
// This is hiding the "Cancel" button:
timePicker.getButton(Dialog.BUTTON_NEGATIVE).setVisibility(View.GONE);
}
});
timePicker.show();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With