5.0系统下的时间选择器效果图:
该项目兼容到3.0下面所以用第三方开源项目:actionbarsherlock,动画效果兼容:nineoldandroids-2.4.0.jar,格式转换器:joda-time-2.1.jar
主要调用代码实例:
import org.joda.time.DateTime;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.text.format.DateFormat;
import android.widget.Toast;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.doomonafireball.betterpickers.calendardatepicker.CalendarDatePickerDialog;
import com.doomonafireball.betterpickers.radialtimepicker.RadialTimePickerDialog;
public class MainActivity extends SherlockFragmentActivity implements CalendarDatePickerDialog.OnDateSetListener, RadialTimePickerDialog.OnTimeSetListener {
public static final String FRAG_TAG_TIME_PICKER = "timePickerDialogFragment";
public static final String FRAG_TAG_DATE_PICKER = "fragment_date_picker_name";
private boolean mHasDialogFrame;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*FragmentManager fm = getSupportFragmentManager();
DateTime now = DateTime.now();
CalendarDatePickerDialog calendarDatePickerDialog = CalendarDatePickerDialog
.newInstance(this, now.getYear(), now.getMonthOfYear() - 1,
now.getDayOfMonth());
calendarDatePickerDialog.show(fm, FRAG_TAG_DATE_PICKER);*/
if (savedInstanceState == null) {
mHasDialogFrame = findViewById(R.id.frame) != null;
}
DateTime now = DateTime.now();
RadialTimePickerDialog timePickerDialog = RadialTimePickerDialog
.newInstance(this, now.getHourOfDay(), now.getMinuteOfHour(),
DateFormat.is24HourFormat(this));
if (mHasDialogFrame) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.frame, timePickerDialog, FRAG_TAG_TIME_PICKER)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.commit();
} else {
timePickerDialog.show(getSupportFragmentManager(), FRAG_TAG_TIME_PICKER);
}
}
@Override
public void onResume() {
// Example of reattaching to the fragment
super.onResume();
/*CalendarDatePickerDialog calendarDatePickerDialog = (CalendarDatePickerDialog) getSupportFragmentManager()
.findFragmentByTag(FRAG_TAG_DATE_PICKER);
if (calendarDatePickerDialog != null) {
calendarDatePickerDialog.setOnDateSetListener(this);
}*/
RadialTimePickerDialog rtpd = (RadialTimePickerDialog) getSupportFragmentManager().findFragmentByTag(
FRAG_TAG_TIME_PICKER);
if (rtpd != null) {
rtpd.setOnTimeSetListener(this);
}
}
@Override
public void onTimeSet(RadialTimePickerDialog dialog, int hourOfDay,
int minute) {
// TODO Auto-generated method stub
String result="" + hourOfDay + ":" + minute;
Toast.makeText(this, result, Toast.LENGTH_SHORT).show();
}
@Override
public void onDateSet(CalendarDatePickerDialog dialog, int year,
int monthOfYear, int dayOfMonth) {
// TODO Auto-generated method stub
String result="Year: " + year + "\nMonth: " + monthOfYear + "\nDay: " + dayOfMonth;
Toast.makeText(this, result, Toast.LENGTH_SHORT).show();
}
}
Theme:
<application android:allowBackup="true" android:icon="@drawable/ic_launcher"
android:label="@string/app_name" android:theme="@style/Theme.Sherlock.Light.DarkActionBar">
界面颜色风格改动:
<?
xml version="1.0" encoding="utf-8"?> <resources> <color name="transparent">#00000000</color> <color name="default_text_color_holo_dark">#ffffffff</color> <color name="default_text_color_holo_dark_disabled">#ff4c4c4c</color> <color name="default_divider_color_dark">#28ffffff</color> <color name="default_button_background_dark">#00000000</color> <color name="default_button_background_pressed_dark">#46c5c1ff</color> <color name="default_keyboard_indicator_color_dark">#ff33b5e5</color> <color name="default_text_color_holo_light">#ff000000</color> <color name="default_text_color_holo_light_disabled">#ffb2b2b2</color> <color name="default_divider_color_light">#28000000</color> <color name="default_button_background_light">#00000000</color> <color name="default_button_background_pressed_light">#ff00ddff</color> <color name="default_keyboard_indicator_color_light">#ff00ddff</color> <color name="white">#ffffff</color> <color name="circle_background">#f2f2f2</color> <color name="line_background">#cccccc</color> <color name="ampm_text_color">#8c8c8c</color> <color name="done_text_color_normal">#000000</color> <color name="done_text_color_disabled">#cccccc</color> <color name="numbers_text_color">#8c8c8c</color> <color name="transparent_black">#7f000000</color> <color name="blue">#33b5e5</color> <color name="blue_focused">#c1e8f7</color> <color name="neutral_pressed">#33999999</color> <color name="darker_blue">#0099cc</color> <color name="date_picker_text_normal">#ff999999</color> <color name="calendar_header">#999999</color> <color name="date_picker_view_animator">#f2f2f2</color> <color name="calendar_selected_date_text">#ffd1d2d4</color> <!-- Colors for red theme --> <color name="red">#ff3333</color> <color name="red_focused">#853333</color> <color name="light_gray">#404040</color> <color name="dark_gray">#363636</color> <color name="line_dark">#808080</color> <color name="done_text_color_dark_normal">#ffffff</color> <color name="done_text_color_dark_disabled">#888888</color> <color name="done_disabled_dark">#bfbfbf</color> <color name="recurrence_picker_background">#fff2f2f2</color> <color name="recurrence_bubble_text_normal">#ff737373</color> </resources>
比方:
<color name="calendar_header">#cfcfcf</color>
改动星期几相应的TextView 的背景色,详细颜色含义參考 Dialog定义
以下是全部源代码下载地址:http://download.youkuaiyun.com/detail/anddroid_lanyan/8839177