没有取消按钮的Timepicker?
作者:互联网
如何创建没有取消按钮的Android时间选择器?我本来希望setCancelable(false)可以做到这一点,但是并不能摆脱按钮,它似乎只是防止取消单击窗口之外或返回按钮.
解决方法:
如果您想使用TimePickerDialog,它非常简单.您只需要检测对话框的显示时间,查找NEGATIVE按钮,因为该按钮可以“取消”,并将其可见性设置为GONE ..像这样:
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();
标签:android-timepicker,android 来源: https://codeday.me/bug/20191119/2034076.html