Reputation: 1837
I'm trying to make the following style in my CalendarView
:
What I managed to do is:
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
Upvotes: 2
Views: 6535
Reputation: 11
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" />
Upvotes: 1
Reputation: 41
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" />
Upvotes: 4
Reputation: 9225
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:
Upvotes: -2