Skip to content

Commit

Permalink
Add ability to change weekdays text color on week bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Anatoliy Shulipov committed Apr 2, 2021
1 parent 8bbc8cc commit dff64a8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -474,20 +474,35 @@ class CalendarView @JvmOverloads constructor(
}

/**
* Sets the days of week bar text color.
* Set text color of days on week bar.
*/
fun setDaysBarTextColor(@ColorInt color: Int) {
calendarStyleAttributes.daysBarTextColor = color
daysBarView.applyStyle(calendarStyleAttributes)
}

/**
* Sets the days of week bar text color resources.
* Set text color of the weekend days on week bar.
*/
fun setDaysBarWeekendTextColor(@ColorInt color: Int) {
calendarStyleAttributes.daysBarWeekendTextColor = color
daysBarView.applyStyle(calendarStyleAttributes)
}

/**
* Set text color of days on week bar.
*/
fun setDaysBarTextColorRes(@ColorRes colorRes: Int) {
setDaysBarTextColor(getColorInt(colorRes))
}

/**
* Set text color of the weekend days on week bar.
*/
fun setDaysBarWeekendTextColorRes(@ColorRes colorRes: Int) {
setDaysBarWeekendTextColor(getColorInt(colorRes))
}

/**
* Sets the month text color.
*/
Expand Down Expand Up @@ -559,6 +574,14 @@ class CalendarView @JvmOverloads constructor(
setDateCellTextColor(colorStateList)
}

/**
* Sets
*/
fun useSeparateWeekendDaysBarTextColor(used: Boolean){
calendarStyleAttributes.useSeparateColorForWeekendDays = used
daysBarView.applyStyle(calendarStyleAttributes)
}

/**
* Add custom [RecyclerView.ItemDecoration] that will be used for the Calendar view decoration.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ internal class DaysBarView @JvmOverloads constructor(

for (i in 0..childCount) {
val dayView = getChildAt(i) as? TextView
dayView?.setTextColor(styleAttributes.daysBarTextColor)
if (i > 4) {
dayView?.setTextColor(styleAttributes.daysBarWeekendTextColor)
} else {
dayView?.setTextColor(styleAttributes.daysBarTextColor)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ internal class CalendarStyleAttributes(
ContextCompat.getColorStateList(context, R.color.calendar_date_text_selector)
),

var dateCellBackgroundShapeForm: Int = R.drawable.calendar_date_shape_form
var dateCellBackgroundShapeForm: Int = R.drawable.calendar_date_shape_form,

)
var useSeparateColorForWeekendDays: Boolean = false

) {

@ColorInt
var daysBarWeekendTextColor: Int = 0
get() = if (field == 0) {
daysBarTextColor
} else {
field
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class CodeStylingDemoFragment : BaseFragment() {

setDaysBarBackgroundColorRes(R.color.custom_calendar_days_bar_background)
setDaysBarTextColorRes(R.color.custom_calendar_days_bar_text_color)
setDaysBarWeekendTextColorRes(R.color.custom_calendar_weekend_days_bar_text_color)

setMonthTextColorRes(R.color.custom_calendar_month_text_color)

Expand Down
1 change: 1 addition & 0 deletions sample/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<color name="custom_calendar_days_bar_background">#0f6c52</color>
<color name="custom_calendar_days_bar_text_color">#f2e81a</color>
<color name="custom_calendar_weekend_days_bar_text_color">@android:color/holo_red_dark</color>

<color name="custom_calendar_date_text_color">#AD000000</color>
<color name="custom_calendar_date_background">#FFFFFF</color>
Expand Down

0 comments on commit dff64a8

Please sign in to comment.