5

I have a CalendarView in my app. But I would like to have the background of the CalendarView black and the text inside the CalendarView white. But in xml there is no TextColor= in the CalendarView. So how can I change the text of the CalendarView?

I have tried every solution on StackOverflow and the internet so far. I've managed to change the color of the days in the CalendarView but not the month and year.

I've tried both methods in this post: Set the text color of calendar view month name

And I've tried this method: Change CalendarView style

And some other I found on the internet but nothing was succesfull.

Community
  • 1
  • 1
Okke Trommelen
  • 165
  • 1
  • 3
  • 12

2 Answers2

8

Set style in your CalendarView

<CalendarView
    android:id="@+id/calendarView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:theme="@style/CalenderViewCustom"
    android:dateTextAppearance="@style/CalenderViewDateCustomText"
    android:weekDayTextAppearance="@style/CalenderViewWeekCustomText" />

Inside Style.xml

    <style name="CalenderViewCustom" parent="Theme.AppCompat">
        <item name="colorAccent">@color/red</item>
        <item name="colorPrimary">@color/white</item>
    </style>

    <style name="CalenderViewDateCustomText" parent="android:TextAppearance.DeviceDefault.Small">
        <item name="android:textColor">@color/white</item>
        <item name="android:weekNumberColor">@color/red</item>
    </style>

    <style name="CalenderViewWeekCustomText" parent="android:TextAppearance.DeviceDefault.Small">
        <item name="android:textColor">@color/white</item>
    </style>
Md Imran Choudhury
  • 9,343
  • 4
  • 62
  • 60
4
android:theme="@style/testTheme"

Use this theme or a custom theme which has parent as this theme.

To make it white

To Choose other than white change the color use the following

android:textColorPrimary="@color/yourColor"

or other text colors use the following

android:weekDayTextAppearance="@style/weekDayTextAppearance"
    android:dateTextAppearance="@style/appTextAppearance"
    android:unfocusedMonthDateColor="@color/colorLoginBtn"
    android:selectedWeekBackgroundColor="@color/colorLoginBtn"
    android:weekSeparatorLineColor="@color/colorLoginBtn"
    android:focusedMonthDateColor="@color/colorLoginBtn"
    android:weekNumberColor="@color/colorLoginBtn"
jafarbtech
  • 6,842
  • 1
  • 36
  • 55