Android日历视图更改文本颜色

5
我在我的应用程序中有一个 CalendarView。但是我希望将 CalendarView 的背景设置为黑色,CalendarView 内部的文本设置为白色。但是,在 XML 中没有 TextColor= 选项可以更改 CalendarView 的文本颜色。那么,我该如何更改 CalendarView 的文本颜色呢?
目前,我已经尝试了 StackOverflow 和互联网上的每种解决方案。我已经成功地更改了 CalendarView 中日期的颜色,但是月份和年份的颜色还未能成功修改。
我尝试了此帖子中的两种方法:Set the text color of calendar view month name 以及这个方法:Change CalendarView style 还尝试了一些其他在互联网上找到的方法,但都没有成功。

2
请查看此前的问题:https://dev59.com/wmox5IYBdhLWcg3wIQ5o - Lorenzo Camaione
2个回答

8
在你的日历视图中设置样式。
<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>

4
这里日历视图中月份名称的颜色是白色。 - AnupamChugh

4
android:theme="@style/testTheme"

使用此主题或具有此主题作为父级的自定义主题。

要使其变为白色

要选择除白色以外的其他颜色,请使用以下内容更改颜色

android:textColorPrimary="@color/yourColor"

或者其他文本颜色,请使用以下内容
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"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接