&l..._android datepicker自定义颜色">
赞
踩
Android DatePicker有两种主流样式 一种类似日历样式,另一种spinner可滑动的样式
设置可滑动样式需要加上一行代码
android:calendarViewShown=“false” 不显示日历样式
然后还可以修改字体颜色
<style name="Theme.picker" parent="android:Theme.Holo.Light">
<item name="android:editTextStyle">@style/Widget.EditText.White</item>
</style>
<style name="Widget.EditText.White" parent="@android:style/Widget.EditText">
<item name="android:textColor">@color/normal</item>
</style>
这样就可以变成白色字体和可滑动样式了
2.代码中应用
<DatePicker
android:id="@+id/datetime_picker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:calendarViewShown="false"
android:layout_alignParentTop="true"
android:layout_marginLeft="@dimen/dp_20"
android:layout_marginRight="@dimen/dp_20"
android:focusable="false"
android:theme="@style/Theme.picker">
</DatePicker>
3.初始化数据
private void getCurData(){ Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("GMT+8:00")); mYear=calendar.get(Calendar.YEAR); Month=calendar.get(Calendar.MONTH)+1; mDay=calendar.get(Calendar.DAY_OF_MONTH); datePicker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), new DatePicker.OnDateChangedListener() { @Override public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { // Log.e(TAG,"year:"+year+"--monthOfYear:"+monthOfYear+"---dayOfMonth:"+dayOfMonth); mYear=year; Month = monthOfYear+1; mDay = dayOfMonth; } }); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。