我正在努力使用Android日历样式。事实证明,android 6忽略了calendarTextColor并使用textColorPrimary来设置日标签以及textColorSecondary来设置几周的样式。我在android 5上检查了calendarTextColor,它运行正常。根据文档textColorPrimary用作工具栏文本颜色。 https://developer.android.com/training/material/theme.html所以我的工具栏文字颜色为白色,我在白色背景上收到白色标签。如何指定calendarTextColor而不触及android api 23的textColorPrimary?
答案 0 :(得分:0)
您可以为日期选择器创建自定义主题并指定文本颜色
试试这个
<style name="datePickerTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorPrimary</item>
<item name="android:textColorPrimary">@color/colorBlack</item>
<item name="android:textColorSecondary">@color/colorBlack</item>
<item name="android:textColorTertiary">@color/colorBlack</item>
</style>
然后您可以在调用DatePickerDialog时指定此主题
final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
myCalendar.set(Calendar.YEAR, year);
myCalendar.set(Calendar.MONTH, monthOfYear);
myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
String myFormat = "MM/dd/yy"; //In which you need put here
SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);
calendar.setText(sdf.format(myCalendar.getTime()));
}
};
calendar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new DatePickerDialog(YourActivity.this,R.style.datePickerTheme, date, myCalendar
.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH)).show();
}
});
}