【问题标题】:Change textcolor of current day in calendar-view在日历视图中更改当天的文本颜色
【发布时间】:2019-10-24 18:19:24
【问题描述】:

我正在尝试在我的CalendarView 中制作以下样式:

我设法做的是:

问题是我站在的日期是白色的,标记也是白色的。

例如,如何将特定日期的颜色更改为黑色?

我的 xml 是:

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

在样式中:

<!-- 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>

此外,如果有办法将日期名称更改为 sun 而不是 s 或 mon 而不是 m,那么很高兴知道 =] 谢谢

【问题讨论】:

  • 不应该把这个:&lt;item name="android:textColor"&gt;@color/colorWhite&lt;/item&gt;改成:&lt;item name="android:textColor"&gt;#000000&lt;/item&gt;
  • ye 但它要么全部改变,要么不改变。我希望所有日期都以白色显示,除了白色圆圈的日期。
  • 有一个库,你可以自定义几乎所有东西,而且它是开源的,所以你可以在任何情况下修改源代码:github.com/ArchitShah248/CalendarDateRangePicker

标签: android android-view android-xml android-styles calendarview


【解决方案1】:

选项 1:

在 CalendarView 中设置样式

<CalendarView
    android:id="@+id/calendarView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:theme="@style/CalenderViewCustom"
    android:dateTextAppearance="@style/CalenderViewDateCustomText"
    android:weekDayTextAppearance="@style/CalenderViewWeekCustomText" />

在 Style.xml 中

<style name="CalenderViewCustom" parent="Theme.AppCompat">
    <item name="colorAccent">@color/red</item>
    <item name="colorPrimary">@color/white</item>
</style>

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

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

选项 2:

android:theme="@style/testTheme"

使用此主题或将父主题作为此主题的自定义主题。

让它变白

要选择白色以外的颜色,请使用以下颜色

android:textColorPrimary="@color/yourColor"

或其他文字颜色使用以下

<CalendarView
    android:weekDayTextAppearance="@style/weekDayTextAppearance"
    android:dateTextAppearance="@style/appTextAppearance"
    android:unfocusedMonthDateColor="@color/colorLoginBtn"
    android:selectedWeekBackgroundColor="@color/colorLoginBtn"
    android:weekSeparatorLineColor="@color/colorLoginBtn"
    android:focusedMonthDateColor="@color/colorLoginBtn"
    android:weekNumberColor="@color/colorLoginBtn"/>

【讨论】:

  • 但与我所写的完全吻合。它是如何解决不同的天色的?
【解决方案2】:

为CalendarView的主题设置样式:重要的是,您必须添加textColorPrimaryInverse是您想要的颜色。

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

然后在 .xml 上设置主题

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

【讨论】:

    【解决方案3】:

    试试下面的代码:

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

    使用上述代码的输出是:

    希望对你有用

    【讨论】:

    • 我想你忘了完成你的答案,CalenderViewCustomCalenderViewWeekCustomText 是参考,但你没有展示如何创建它们。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 2011-01-22
    相关资源
    最近更新 更多