更改 CalendarView 中的 "Month" 文本颜色
Change "Month" text color in CalendarView
我研究了使用自定义主题通过各种标签设置 textColor 的多个选项,但 none 似乎可行。我已附上屏幕截图以供参考。这是我在应用程序主题为深色时使用的自定义主题。
<style name="CalendarWeekDateTextDark" parent="TextAppearance.AppCompat.Button">
<item name="android:textColor">@color/colorWhite</item>
</style>
我在 XML 文件中将其用作
<CalendarView
android:id="@+id/calendarView"
android:layout_width="0dp"
android:layout_height="0dp"
android:dateTextAppearance="?attr/CalendarWeekDatTextDark"
android:weekDayTextAppearance="?attr/CalendarWeekDatTextDark"
app:layout_constraintBottom_toTopOf="@+id/bottomGuideline"
app:layout_constraintEnd_toEndOf="@+id/endGuideline"
app:layout_constraintStart_toStartOf="@+id/startGuideline"
app:layout_constraintTop_toBottomOf="@+id/topGuideline" />
截图:
在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>
然后在xml:
<CalendarView
android:theme="@style/CustomCalendarMonth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:dateTextAppearance="@style/CustomCalendarDay"
android:weekDayTextAppearance="@style/CustomCalendarWeek" />
输出如下:
我研究了使用自定义主题通过各种标签设置 textColor 的多个选项,但 none 似乎可行。我已附上屏幕截图以供参考。这是我在应用程序主题为深色时使用的自定义主题。
<style name="CalendarWeekDateTextDark" parent="TextAppearance.AppCompat.Button">
<item name="android:textColor">@color/colorWhite</item>
</style>
我在 XML 文件中将其用作
<CalendarView
android:id="@+id/calendarView"
android:layout_width="0dp"
android:layout_height="0dp"
android:dateTextAppearance="?attr/CalendarWeekDatTextDark"
android:weekDayTextAppearance="?attr/CalendarWeekDatTextDark"
app:layout_constraintBottom_toTopOf="@+id/bottomGuideline"
app:layout_constraintEnd_toEndOf="@+id/endGuideline"
app:layout_constraintStart_toStartOf="@+id/startGuideline"
app:layout_constraintTop_toBottomOf="@+id/topGuideline" />
截图:
在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>
然后在xml:
<CalendarView
android:theme="@style/CustomCalendarMonth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:dateTextAppearance="@style/CustomCalendarDay"
android:weekDayTextAppearance="@style/CustomCalendarWeek" />
输出如下: