Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Month text color in CalendarView

I use CalendarView in my project and I need to make a special design for it. I can change colours of all things in CalendarView but only not colour of month on the top of calendar. I tried all attributes in xml. How I can change colour of month incription and arrows?

<CalendarView
        android:id="@+id/calendarID"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="Heh"
        android:maxDate="31/12/2018"
        android:minDate="09/01/2012"
        android:showWeekNumber="false"
        android:focusedMonthDateColor="@android:style/TextAppearance.Small"
        android:background="#004366"
        android:unfocusedMonthDateColor="@android:style/TextAppearance.Small"
        android:dateTextAppearance="@android:style/TextAppearance.Small"
        android:weekDayTextAppearance="@android:style/TextAppearance.Small"
        android:weekSeparatorLineColor="@android:style/TextAppearance.Small"
        android:selectedWeekBackgroundColor="@android:style/TextAppearance.Small"
        />

enter image description here

 LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService
            (Context.LAYOUT_INFLATER_SERVICE);

    LinearLayout ll= (LinearLayout)inflater.inflate(R.layout.calendar_moi, null, false);

    CalendarView cv = (CalendarView) ll.getChildAt(0);
    Long maxData = System.currentTimeMillis();
    cv.setMaxDate(maxData);

    cv.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {

        @Override
        public void onSelectedDayChange(CalendarView view, int year, int month,
                                        int dayOfMonth) {


        }
    });

    new AlertDialog.Builder(ItemClassActivity.this)
            .setTitle("")
            .setMessage("")
            .setView(ll)
            .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {

                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {

                }
            }
    ).show();
like image 298
Valentin Avatar asked Jan 24 '19 09:01

Valentin


1 Answers

Having defined following in styles.xml:

<style name="CustomCalendarMonth" parent="AppTheme">
    <item name="android:textColorPrimary">@color/orange</item>
</style>

<style name="CustomCalendarDay" parent="TextAppearance.MaterialComponents.Caption">
    <item name="android:textColor">@color/green</item>
</style>

<style name="CustomCalendarWeek" parent="TextAppearance.MaterialComponents.Caption">
    <item name="android:textColor">@color/purple</item>
</style>

Then in xml:

<CalendarView
    android:theme="@style/CustomCalendarMonth"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:dateTextAppearance="@style/CustomCalendarDay"
    android:weekDayTextAppearance="@style/CustomCalendarWeek" />

Here will be the output:

like image 114
azizbekian Avatar answered Oct 14 '22 11:10

azizbekian