You can get hour of the day using this:
int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
HOUR_OF_DAY will give you 24-hour time. Then just check something like this:
if (hour >= 22 && hour <= 9) button.setEnabled(false);
Now there are few options to disable the button. You can use:
setClickable(false)
setEnabled(false)
setOnClickListener(null)
Notice that if you setOnClickListener(null)
then you need to set your listener again if the time is correct.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…