编程语言
首页 > 编程语言> > Java-Android日历视图更改文本颜色

Java-Android日历视图更改文本颜色

作者:互联网

我的应用程序中有一个CalendarView.但是我想让CalendarView的背景为黑色,而CalendarView内的文本为白色.但是在xml中,CalendarView中没有TextColor =.那么,如何更改CalendarView的文本?

到目前为止,我已经在StackOverflow和Internet上尝试了所有解决方案.我设法更改了CalendarView中日期的颜色,但没有更改月份和年份.

我在这篇文章中尝试了两种方法:Set the text color of calendar view month name

我已经尝试过这种方法:
Change CalendarView style

我在互联网上发现了其他一些东西,但没有成功.

解决方法:

Set style in your 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" />

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

标签:calendarview,java,android
来源: https://codeday.me/bug/20191027/1941238.html