2

I'm trying to make the following style in my CalendarView:

enter image description here

What I managed to do is:

enter image description here

Thing is that the color of the date where im standing on is white and the marker is white as well.

How can I change the color of this specific day to black for example?

My xml is:

<CalendarView
    android:id="@+id/cv_BorrowCalendar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/cv_background"
    android:theme="@style/CalenderViewCustom"
    android:dateTextAppearance="@style/CalenderViewDateCustomText"
    android:weekDayTextAppearance="@style/CalenderViewWeekCustomText"
    app:layout_constraintBottom_toTopOf="@+id/bottom_navigation"
    app:layout_constraintTop_toBottomOf="@+id/rv_Borrowing" />

and in Styles:

<!-- Calendar -->
<style name="CalenderViewCustom" parent="Theme.AppCompat">
    <item name="colorAccent">@color/colorWhite</item>
    <item name="colorPrimary">@color/colorWhite</item>
</style>

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

<style name="CalenderViewWeekCustomText" parent="android:TextAppearance.DeviceDefault.Small">
    <item name="android:textColor">@color/colorWhite</item>
</style>

Also if there is a way to change the day names to sun instead of s or mon instead of m it would be nice to know =] Thank you

Ricardo A.
  • 685
  • 2
  • 8
  • 35
Ben
  • 1,737
  • 2
  • 30
  • 61
  • Shouldn't this: `@color/colorWhite` be changed to : `#000000` – Sachin Bahukhandi Oct 24 '19 at 18:32
  • ye but it either changes all or none. I want all dates to show in white color except for the one where the white circle. – Ben Oct 24 '19 at 18:51
  • There's a library where you can customize pretty much everything, and it's open source, so you can just modify the source code in any case: https://github.com/ArchitShah248/CalendarDateRangePicker – Ricardo A. Oct 24 '19 at 20:08
  • related: https://stackoverflow.com/questions/15874175/changing-color-of-single-day-in-calendarview-android – Ricardo A. Oct 24 '19 at 20:28

3 Answers3

4

Set style for theme of CalendarView: important, you have to add textColorPrimaryInverse is your color you want.

<style name="CalenderViewCustom" parent="yourAppBase">
    <item name="colorControlActivated">@color/bg_app_base</item>
    <item name="android:textColorPrimaryInverse">@color/white</item>  // color of date selected.
</style>

then set theme on .xml

<CalendarView
   android:id="@+id/calendarView"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:theme="@style/CalenderViewCustom" />
0

Hi I might be late to the show but this is how I have done it if anyone else has this question and finds this thread :-) You need to use a selector color in order to achieve what you want while overriding the theme with dateTextAppereance (in case you want a custom color for the header as well).

<style name="CustomCalendarMonth" parent="Theme.YourApp">
    <item name="android:textColorPrimary">?attr/colorPrimary</item>
</style>

<style name="CustomCalendarDay" parent="Theme.YourApp">
    <item name="android:textColor">@color/itr_custom_calendar_day_selector_color</item>
</style>

And the

@color/itr_custom_calendar_day_selector_color

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_activated="true" android:color="?attr/colorOnPrimary" />
    <item android:state_activated="false"  android:color="?android:attr/textColor" />
</selector>

Finally the CalendarView in xml.

<CalendarView
   android:id="@+id/calendar"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:dateTextAppearance="@style/CustomCalendarDay"
   android:theme="@style/CustomCalendarMonth" />
-2

Try below code:

<CalendarView
    android:id="@+id/cv_BorrowCalendar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/cv_background"
    android:theme="@style/CalenderViewCustom"
    android:weekDayTextAppearance="@style/CalenderViewWeekCustomText"/>

The output using above code is:

enter image description here I hope it works for you

Android Geek
  • 8,956
  • 2
  • 21
  • 35
  • I think you forgot to finish your answer,`CalenderViewCustom` and `CalenderViewWeekCustomText` are reference but you didn't show how to create them. – nategurutech Jan 12 '21 at 00:45