TimePicker without cancel button?
•
Android
How do I create an Android time selector without a cancel button? I had hoped that setcancelable (false) could do this, but it didn't get rid of the button. It just seemed to prevent canceling clicking outside the window or returning to the button
resolvent:
If you want to use timepickerdialog, it is very simple. You only need to check the display time of the dialog box and find the negative button, because the button can be "cancelled" and set its visibility to go.. 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();
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码