【问题标题】:Change "Month" text color in CalendarView在 CalendarView 中更改“月份”文本颜色
【发布时间】:2020-03-09 18:57:43
【问题描述】:

我研究了使用自定义主题通过各种标签设置 textColor 的多个选项,但它们似乎都不起作用。我附上了截图供参考。这是我在应用主题为深色时使用的自定义主题。

<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" />

截图:

【问题讨论】:

    标签: java android android-layout android-view calendarview


    【解决方案1】:

    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" />
    

    输出如下:

    【讨论】:

    • 谢谢!帮我清除了很久的bug。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-23
    • 2012-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多