我有一个 DatePicker,我在其中禁用了 SpinnerView,现在只使用 CalendarView。但它从星期天开始,我想用星期一作为一周的第一天。我该如何改变呢?我猜第一天将取决于手机设置,但在我的瑞士手机上它仍然是错误的......
我还没有找到任何 set Method 或任何 XML 命令。
<DatePicker
android:id="@+id/date_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" />
和
DatePicker datePicker = (DatePicker) convertView.findViewById(R.id.date_picker);
datePicker.setSpinnersShown(false);
- - - - - - 编辑: - - - - - -
我试图改变语言环境:
Locale.setDefault(Locale.GERMAN);
但这并没有改变任何以太。所以我阅读了 android-17.android.widget.DatePicker.java 我发现:
public DatePicker(Context context, AttributeSet attrs, int defStyle) {
//...
// initialization based on locale
setCurrentLocale(Locale.getDefault());
//...
}
/**
* Sets the current locale.
*
* @param locale The current locale.
*/
private void setCurrentLocale(Locale locale) {
if (locale.equals(mCurrentLocale)) {
return;
}
mCurrentLocale = locale;
mTempDate = getCalendarForLocale(mTempDate, locale);
mMinDate = getCalendarForLocale(mMinDate, locale);
mMaxDate = getCalendarForLocale(mMaxDate, locale);
mCurrentDate = getCalendarForLocale(mCurrentDate, locale);
mNumberOfMonths = mTempDate.getActualMaximum(Calendar.MONTH) + 1;
mShortMonths = new String[mNumberOfMonths];
for (int i = 0; i < mNumberOfMonths; i++) {
mShortMonths[i] = DateUtils.getMonthString(Calendar.JANUARY + i,
DateUtils.LENGTH_MEDIUM);
}
}
/**
* Gets a calendar for locale bootstrapped with the value of a given calendar.
*
* @param oldCalendar The old calendar.
* @param locale The locale.
*/
private Calendar getCalendarForLocale(Calendar oldCalendar, Locale locale) {
if (oldCalendar == null) {
return Calendar.getInstance(locale);
} else {
final long currentTimeMillis = oldCalendar.getTimeInMillis();
Calendar newCalendar = Calendar.getInstance(locale);
newCalendar.setTimeInMillis(currentTimeMillis);
return newCalendar;
}
}
那么为什么 Locale.setDefault(Locale.GERMAN) 不起作用?!正如您在上面看到的,我从 XML 中获取了 DatePicker .. 有什么错误吗?!