我需要更改DatePicker的字体颜色,它被视为日历。我发现的所有回复都适合微调器视图。那么有没有办法在日历视图中更改字体颜色?
答案 0 :(得分:0)
您可以使用getDeclaredFields()方法
执行此操作示例:我在这里更改了文本大小和填充,这对我有用。
DatePicker datepicker = (DatePicker) findViewById(R.id.datePicker);
try {
Field f[] = datepicker.getClass().getDeclaredFields();
for (Field field : f)
{
if (field.getName().equals("mYearPicker"))
{
field.setAccessible(true);
Object yearPicker = new Object();
yearPicker = field.get(datepicker);
((View) yearPicker).setVisibility(View.VISIBLE);
((View) yearPicker).setPadding(-2, 0, -2, 0);
View childpicker;
childpicker = (View) findViewById(Resources.getSystem().getIdentifier("year", "id","android"));
EditText textview = (EditText) childpicker.findViewById(Resources.getSystem().getIdentifier("timepicker_input", "id", "android"));
textview.setTextSize(26);
textview.setPadding(-3, 0, -3, 0);
//System.out.println("ss1:"+field);
}
if (field.getName().equals("mDayPicker"))
{
field.setAccessible(true);
Object yearPicker = new Object();
yearPicker = field.get(datepicker);
((View) yearPicker).setVisibility(View.VISIBLE);
((View) yearPicker).setPadding(-2, 0, -2, 0);
View childpicker;
childpicker = (View) findViewById(Resources.getSystem().getIdentifier("month", "id","android"));
EditText textview = (EditText) childpicker.findViewById(Resources.getSystem().getIdentifier("timepicker_input", "id", "android"));
textview.setTextSize(26);
textview.setPadding(-3, 0, -3, 0);
//System.out.println("ss2:"+field);
}
if (field.getName().equals("mMonthPicker"))
{
field.setAccessible(true);
Object yearPicker = new Object();
yearPicker = field.get(datepicker);
((View) yearPicker).setVisibility(View.VISIBLE);
((View) yearPicker).setPadding(-2, 0, -2, 0);
View childpicker;
childpicker = (View) findViewById(Resources.getSystem().getIdentifier("day", "id","android"));
EditText textview = (EditText) childpicker.findViewById(Resources.getSystem().getIdentifier("timepicker_input", "id", "android"));
textview.setTextSize(26);
textview.setPadding(-3, 0, -3, 0);
//System.out.println("ss3:"+field);
}
//System.out.println("ss:"+field);
}
} catch (SecurityException e) {
Log.d("ERROR", e.getMessage());
} catch (IllegalArgumentException e) {
Log.d("ERROR", e.getMessage());
} catch (IllegalAccessException e) {
Log.d("ERROR", e.getMessage());
}catch (Exception e) {
Log.d("ERROR", e.getMessage());
}
答案 1 :(得分:0)
使用此链接我已经使用xml将清单添加到清单