android提供的TimePicker控件
效果:
使用方法:
// 获取当前时间 Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("GMT+8")); if (mHour == -1 && mMinute == -1) { mHour = calendar.get(Calendar.HOUR_OF_DAY); mMinute = calendar.get(Calendar.MINUTE); } mTimePicker = (TimePicker) findViewById(R.id.timePicker); mTimePicker.setCurrentHour(mHour); mTimePicker.setCurrentMinute(mMinute); mTimePicker .setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Override public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { mHour = hourOfDay; mMinute = minute; } });
时间: 2024-10-27 07:20:30