0

I need to change font color for DatePicker, which is viewed as calendar. All responses that I found are suitable for spinners view. So is there a way to change font color in calendar view?

Mykhailo Granik
  • 368
  • 8
  • 23
  • http://stackoverflow.com/questions/18584934/custom-datepicker-in-android please look at this thread –  Jan 06 '14 at 12:32
  • @user3110424 I think you misunderstood my question. I already have a datepicker with android:calendarViewShown="true". All I need is to change it's color – Mykhailo Granik Jan 06 '14 at 12:36
  • https://github.com/SimonVT/android-datepicker. check this if it helps. and this http://stackoverflow.com/questions/20148671/android-how-to-change-the-color-of-the-datepicker-divider which uses reflection to change the divider color. – Raghunandan Jan 06 '14 at 12:38

2 Answers2

0

You can do this using getDeclaredFields() method

Sample: Here I changed textsize and padding and it works for me.

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());
    }
Ketan Ahir
  • 6,678
  • 1
  • 23
  • 45
0

Use this link i have done with xml in adding theme to the manifest

Android HoneyComb DatePicker Text Color

Community
  • 1
  • 1
Meenal
  • 2,879
  • 5
  • 19
  • 43